I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$
select FineAmount from tickets
Thanks
SQL Server ROUND() Function The ROUND() function rounds a number to a specified number of decimal places.
Decimal data type value with positive LengthSELECT ROUND(@value, 1); SELECT ROUND(@value, 2); SELECT ROUND(@value, 3); In this example, we can see that with decimal values round up to the nearest value as per the length.
The ROUND() function rounds a number to a specified number of decimal places. Tip: Also look at the FLOOR() and CEILING() functions.
select round(FineAmount*2,-1)/2 from tickets
or to put nicholaides suggestion in sql
select round(FineAmount/5,0)*5 from tickets
The example assumes that FineAmount is of type money. The second approach is probably better as the first one works with the limit of maximum_value_of_money_type/2
More on ROUND
A general math solution:
Divide by 5, round to the nearest integer, then multiply by 5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With