Reputation: 1529
I have a number and I use ROUND() function in SQL :
SELECT ROUND(1.81999,2,1)
I want the result 1.82, not 1.81.
I don't know where my mistake is.
Upvotes: 0
Views: 359
Reputation: 2923
The answer is simple. you are specifying 1 in the Function command (3rd parameter of the ROUND() command.
a quote from MSDN about this parameter:
When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.
Just change that 1 at the end to a 0 or ommit it entirely and problem solved
Upvotes: 1
Reputation: 2066
SELECT ROUND(1.81999,2,1) Will truncate the result. so the result is 1.81
use this to perform original rounding SELECT ROUND(1.81999,2).
Upvotes: 3
Reputation: 68962
See Section "Round to truncate" of Round(Transact-SQL)
This probably depends on the SQL-Dialect you use.
Upvotes: 0
Reputation: 123831
mysql? just ROUND(...,2) work for me.
mysql> SELECT ROUND(1.81999,2);
+------------------+
| ROUND(1.81999,2) |
+------------------+
| 1.82 |
+------------------+
1 row in set (0.00 sec)
mysql>
Upvotes: 2