Author |
Topic  |
|
Ciupaz
Posting Yak Master
Italy
232 Posts |
Posted - 03/15/2011 : 04:10:15
|
Hi all, why if I write:
SELECT ROUND(0.6, 0)
I got this error:
Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expression to data type numeric.
I'm using SQL Server 2008 version 10.50.1600.
Why this happen?
Thanks a lot.
Luigi
|
|
Lumbago
Norsk Yak Master
Norway
3271 Posts |
|
jimf
Flowing Fount of Yak Knowledge
USA
2875 Posts |
Posted - 03/15/2011 : 06:56:52
|
SELECT ROUND(0.6, 1) Works. Maybe it's considering 0.6 a numeric(1,1) and can't round it up?
Jim
Everyday I learn something that somebody else already knew |
 |
|
sunitabeck
Flowing Fount of Yak Knowledge
5155 Posts |
|
Ciupaz
Posting Yak Master
Italy
232 Posts |
Posted - 03/15/2011 : 07:29:39
|
Thank you all, so I have to pay attention to the second parameter of the ROUND function.
Luigi
|
 |
|
Lumbago
Norsk Yak Master
Norway
3271 Posts |
|
sunitabeck
Flowing Fount of Yak Knowledge
5155 Posts |
Posted - 03/15/2011 : 07:44:05
|
Seems to show the same behavior whenever precision changes.select round(0.96,1);
select round(0.996,2);
select round(0.9996,3); |
 |
|
Lumbago
Norsk Yak Master
Norway
3271 Posts |
|
Lumbago
Norsk Yak Master
Norway
3271 Posts |
|
sqller
Starting Member
USA
1 Posts |
|
sunitabeck
Flowing Fount of Yak Knowledge
5155 Posts |
Posted - 04/20/2011 : 20:58:16
|
I think that is consistent with the "Return type of round() is the same as the input" statement. Because you did the casting, input type now is float and so the return type is float as well.
When you don't do the casting, 0.6 is of type decimal(1,1). So the return type is also decimal(1,1), which can hold only a maximum of 0.9.
It is a chore to have to cast decimals to float (or to a larger decimal type) before rounding - not to mention precision issues with float etc.
|
 |
|
|
Topic  |
|