frimy
asked on
SQL, round to the nearest whole number
Hello all,
How to round to the nearest whole number in SQL
e.i.
.03 = 1
1.03 = 2
if there is a remaining i want to add 1.
Thanks
How to round to the nearest whole number in SQL
e.i.
.03 = 1
1.03 = 2
if there is a remaining i want to add 1.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another solution for you.
/*------------------------
SELECT CASE WHEN CAST(a AS FLOAT) LIKE '%.%' THEN CAST(1 + a AS INT) ELSE a END
FROM
(
SELECT (.03) a
UNION ALL
SELECT (1.03)
UNION ALL
SELECT 2
UNION ALL
SELECT 5
)r
------------------------*/
---------------------------------------
1.00
2.00
2.00
5.00
(4 row(s) affected)
Actually strictly speaking 1.03 rounded to the nearest whole number is 1 not 2. For this one usually uses bankers rounding
int (value + .45)
int (value + .45)
@Author - did u tried my suggestions, both are giving exactly same output you need. Thanks
ASKER
Thanks
I wasn't sure what ceiling does.
it works fine
have a nice day!
I wasn't sure what ceiling does.
it works fine
have a nice day!
Open in new window