4

Possible Duplicate:
Precision, Scale, Sum, Divide.. Truncation

I've got a question. I've programmed a function but I'm having some problems when I divide 2 numbers using convert. Here is an example:

Declare @A Numeric(18,6)
Declare @B Numeric(18,6)

Set @A = 1
Set @B = 130

If i do the following query the result is : 0.007692307692307692

Select Convert(Decimal(30,18),@A / @B)

But if I do this the result is: 0.007692300000000000 (losing decimals)

Select Convert(Decimal(30,18),Convert(Decimal(30,18),@A) / Convert(Decimal(30,18),@B))

Can someone please explain why I'm losing decimals if I'm using the same precision and scale?

Community
  • 1
  • 1
Pedro
  • 75
  • 6
  • 2
    When the theoretical precision from division exceeds 38 scale gets truncated to 6 decimal places. The theoretical precision formula for division of decimal/decimal is documented in books online. – Martin Smith Dec 12 '12 at 21:15
  • 2
    Instead of jumping twice through that old (nicely answered SO question), here's the end link: http://blogs.msdn.com/b/sqlprogrammability/archive/2006/03/29/564110.aspx – RichardTheKiwi Dec 12 '12 at 21:27

0 Answers0