Quantcast
Viewing all articles
Browse latest Browse all 3160

SQL Server Custom Rounding

I have a situation where :

24.9999 should be 25 24.5000 should be 25 24.4999 should be 24 24.1111 should be 24

I tried Ceiling , but the result will be 25, where Floor will be 24 for all of them.

How to accomplish this?

Thanks a lot for your time.

Note: it might be helpful to let you know that I want this functionality to be inside a computed column .

Use:

Round(YourNumber, 0)

The 0 indicates the precision (i.e. number of decimal places); if you wanted to round 42.51 to 42.5, you'd replace the 0 with 1, for example.

Make sure not to use float s - they can sometimes be approximated, which causes values to be rounded incorrectly on occasion.


Viewing all articles
Browse latest Browse all 3160

Trending Articles