Link to home
Start Free TrialLog in
Avatar of Larry Brister
Larry BristerFlag for United States of America

asked on

Round decimal to nearest .25

Is there a way to round a decimal to nearest .25%?


Select 3.6333  would return 3.75 and
           3.6222 would return  3.50
Avatar of HomerTNachoCheese

multiply by 4, round to nearest whole number, divide by 4.
Avatar of HomerTNachoCheese

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scott Pletcher
Or, one other alternative:

floor((value + 0.12) / 0.25) * 0.25

select value, floor((value + 0.12) / 0.25) * 0.25 as rounded_value
from (
    select 3.6333 as value union all --would return 3.75
    select 3.6222 --would return  3.50
) as data
Scott - I think you may be slightly off.  3.63 would be the point where your number begins to round up to 3.75, but it should start rounding up at 3.625.

The alternative would be floor((value + 0.125) / 0.25) * 0.25

I am using the floor function in another program to test, but I do think it should be 0.125, not 0.12.
OK, 0.125 makes sense.

I was trying to find a method where you could round at any value, such as .15, rather than using something like "* 4", where it requires having an even multiple and re-calculating the multiplier.
Avatar of Larry Brister


Cleanest answer for me