Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > dotnet ado.net > february 2006 >

dotnet ado.net : SqlDataType.Decimal rounds to zero !?



Andre Ranieri
2/27/2006 5:25:16 PM
Hi, I'm writing a module to insert records to the main accounts table in our
CRM database. I've noticed in testing that the tax percent, which is a
decimal data type with length 5, default value (0), precision 9 and scale 6
always enters zero.

I've noticed if I run the test T-SQL statement it always returns a value of
0.0 instead of 0.085.

Any ideas on what I'm missing would be hugely appreciated, I'm sort of
tearing my hair out here.

Thanks,

Andre

declare @taxpercent decimal(5)
set @taxpercent = 0.085000
Andre Ranieri
2/27/2006 7:56:27 PM

Stephany,

Thanks, you explanation made a lot of sense.

I'd read this on BOL earlier but it hadn't clicked until I read your post.

Andre Ranieri



[quoted text, click to view]
Stephany Young
2/28/2006 12:00:00 AM
The length 0f 5 that you refer to is the numbers of bytes that SQL Server
uses to store the value in.

From a logical point of view the variable, requiring precision 9 and scale 6
must be declared as:

declare @taxpercent decimal(9,6)

decimal(5) is the same as decimal(5,0) which is precision 5 and scale 0 and
the result you are observing is completely correct.


[quoted text, click to view]

AddThis Social Bookmark Button