We help IT Professionals succeed at work.

Round decimal to nearest .25

3,371 Views
Last Modified: 2012-05-31
Is there a way to round a decimal to nearest .25%?

Example

Select 3.6333  would return 3.75 and
           3.6222 would return  3.50
Comment
Watch Question

multiply by 4, round to nearest whole number, divide by 4.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Scott PletcherSenior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
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.
Scott PletcherSenior DBA
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
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.
Larry Bristersr. Developer

Author

Commented:
Cleanest answer for me
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.