I want to use ROUNDDOWN function.
When i tried using the following query,it gives me an error saying "'rounddown' is not a recognized built-in function name."
select rounddown(25.227,2)
My requirement is to rounddown the value to two decimals
for ex: for value 25.22789 result should be 25.22
and round up also
for ex: for value 25.22789 result should be 25.23
Any help?
Thanks in advance
SQL Server ROUND() Function The ROUND() function rounds a number to a specified number of decimal places.
In Oracle, MySQL, and PostgreSQL, you can use either the CEIL() or CEILING() function to round up.
A general math solution: Divide by 5, round to the nearest integer, then multiply by 5.
Notice that we need a complex expression involving CEILING, in order to get the "rounded up to next 1000" number that you wanted. The "trick" (if you want to call it that) is to divide by 1000.0, which forces a decimal result, before applying the CEILING.
Use third parameter of ROUND()
function to truncate and then CONVERT()
it to DECIMAL(x, 2)
to get rid of unwanted trailing zeros.
Fiddle demo
SELECT CONVERT(DECIMAL(10,2), ROUND(25.227, 2, 1)) RoundDown,
CONVERT(DECIMAL(10,2), ROUND(25.227, 2, 0)) RoundUp
Results
| RoundDown | RoundUp |
|-----------|---------|
| 25.22 | 25.23 |
I think you are looking for either CEILING()
or floor()
function like
select CEILING(25.227) //results in 26
(OR)
select FLOOR(25.227) //Results in 25
EDIT:
for ex: for value 25.22789 result should be 25.22
You can try like below
select round(25.22789, 2, 2)
Which will result in 25.22000
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