> I'm trying to do some simple calculations with System.Data.SqlDecimal on
> .NET 2.0:
[quoted text clipped - 18 lines]
> Any explanations? Thanks!
> Beat
Sure. This explains all:
Precision, Scale, and Length (Transact-SQL)
http://msdn2.microsoft.com/en-us/library/ms190476.aspx
Given decimals e1 and e1, with precision p1 and p2 and scale s1 and s2
respectively, the quotient (e1 / e2)
will have precision = p1 - s1 + s2 + max(6, s1 + p2 + 1) and scale = max(6,
s1 + p2 + 1)
In a table or in TSQL a decimal type is declared with a precision and scale.
When you use this .NET constructor the precision and scale are inferred from
the constructor argument. If you want more precision in the quotient you
can specify more precision in the arguments:
SqlDecimal one = SqlDecimal.ConvertToPrecScale(new SqlDecimal(1), 20,
12);
SqlDecimal seven = SqlDecimal.ConvertToPrecScale(new SqlDecimal(7), 20,
12); ;
SqlDecimal oneBySeven = SqlDecimal.Divide(one, seven);
Console.WriteLine(oneBySeven);
David