Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Data type problem

Author  Topic 

sqlbug
Posting Yak Master

201 Posts

Posted - 2012-03-21 : 17:59:27
Hi, I have this table with a column data type of numeric(8,4).

The problem is - it's automatically rounding the data. For example: 3.4999945 gets rounded to 3.5, but I don't want that and I want to keep it exactly as calculated with all the digits after decimal.

How can I do this, or change it to a different data type? I tried from
numeric(8,4) to numeric(8,7), get arithmetic overflow error.

Thanks.

sqlbug

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-21 : 18:17:40
declare @var numeric(8,7)
set @var=3.4999945
select @var

no error


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-21 : 18:19:15
try numeric(11,7)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2012-03-21 : 18:26:49
If that (11,7) works - is it going to stop the rounding?
Thanks.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-21 : 18:33:36
if there are no values with more than 7 digits to right of the decimal point - yes


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2012-03-22 : 11:17:51
Unfortunately, it still rounds 3.499995 to 3.5. I was looking at msdn and it says numeric and decimal does the automatic rounding.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-03-22 : 11:42:33
Maybe you can show us the statement where you think it happens?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2012-03-22 : 14:32:39
Sorry - my bad, forgot about a 3rd table involved where the type was still numeric(8,4) - that was causing the rounding.
Thanks very much - webfred. It's resolved.
Go to Top of Page
   

- Advertisement -