rounding special case
ultima
Member, PRO Posts: 1,207
Hi guys, need a little help rounding numbers in a special case, and was wandering if i can get help from brilliant minds in the community
X.X number needs to be rounded down, to nearest .5 or rounded up depending on the decimal number.
for example.
.1, .2 gets rounded down to .0
.3 -.7 gets rounded to .5
.8, .9 gets rounded up.
i'm fiddling with mod and ceil / floor with no success.
thanks in advance.
Comments
abs(round( X*2)/2)
Explanation . . . . .
X is the value you want to round.
The abs function forces positive values, this is to account for the (odd) inclusion of the one negative value (-0.7).
so this will work for .3, .4 (round to .5) and .6 and .7 (rounded down to .5 as well)?
will give it a try.. it'll be like math wizardry .. you guys are the best.
it works perfectly! thank you Socks
as I said Wizardry!
@Socks -- Nice solution!
Cheers !
Here's something odd that I don't really understand, when using roundTo(x,y) you will - as you know - get x with y decimal places.
So . . . .
roundTo (0.5,1) will give you 0.5
roundTo (0.5,0) will give you 0
. . . but when you round something to 0.5 places (I know, I know ! ) you get some, to me, counterintuitive results . . . for example:
roundTo (0.5,0.5) will give you 0.63245553203368 - which is the square root of 0.4 !?
roundTo (1,0.5) will give you 0.94868329805051 - which is the square root of 0.9 !?
I know you're probably thinking 'don't mess with rounding values to non-existent decimal places, it's pointless and you will eventually go blind', but if you could explain it to me in less than 15 words I would be very thankful.
Good !
Gulp!!
Um.... rounding error?
I think it might be aliens ?