Hi,
I want all decimal places round to 0.5 ( Result B in the picture). Any help ?
Thank you.
Round all Decimals to 0.5.gh (6.0 KB)
I like this, but it doesn’t deliver the result asked for in the opening post, where it would seem that any decimal number that is not a whole number rounds to a x.5. Wondering if this could still be done by math rather than with Cumberland’s string operations.
Created a GHPython script that can do this:
Round all Decimals to 0.5_v2.gh (10.3 KB)
Thank you too much.
I missed that 11.9 result should be 11.5
I’d be uncomfortable relying on 0.00001
That’s neat. Just a note that there’s a native function for getting the “fractional and integer parts of x”, which can simplify things a bit:
241120_FloatToHalfDecimal.gh (5.1 KB)
Here is a solution using vanilla Grasshopper, a conditional and math:
(Edited. Mistakes were made)
What this essentially does is shift the values by 0.5, so that multiples of 0.5 can be rounded to as though they are whole number bounds. Then true whole numbers are eliminated from this process (mod=0 is excepted)
Effectively, this works just as the native function allowing any decimal number to be rounded to.