SQL Server Decimal precision -
Text after
declared @nr1 decimal (20,19), @ NR2 decimal (20,19) set @nr1 = exp (1.0) Set @ NR2 = PI (); Print @ nr1 / nr2
There are "infinite" numbers in the form of XP and PI, you must have enough decimal to print
As a result of this query 0.865255979432265082
For query:
Announce @nr12 decimal (34,25), @ nr22 decimal (34,25) set @ NR12 = XP (1.0) set @ NR22 = PI (); Print @ nr12 / @ nr22
I get the result: 0.8,65,255
So my question is, why the first query More accurate then second one? As it is defined in decimal (P, S)
as defined in MSDN, it tells me that the second query should be more accurate.
This link will help you:
According to this, a division e1 / e2 The result of this formula is maximum (6, s1 + p2 + 1) and includes this note:
- The result is accurate and the scale is a full maximum of 38. When the result is more than the exact 38, the respective scale is reduced to prevent integral part of a result from being cut.
Perhaps you would be better at using decimal (19, 16) because the scale for exp () and pi () in both cases is 16.
Comments
Post a Comment