Avatar of Larry Brister
Larry Brister
Flag for United States of America asked on

Round decimal to nearest .25

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
Microsoft SQL Server 2005Microsoft SQL ServerMicrosoft Development

Avatar of undefined
Last Comment
Larry Brister

8/22/2022 - Mon
HomerTNachoCheese

multiply by 4, round to nearest whole number, divide by 4.
Mez4343

ASKER CERTIFIED SOLUTION
HomerTNachoCheese

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
HomerTNachoCheese

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 Pletcher

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 Brister

ASKER
Cleanest answer for me
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.