Parameters
- input
- The TdNumber that is to be converted to a
System.Decimal
value.
Return Value
System.Decimal
value that is equivalent to the TdNumber is returned.System.Decimal
value.
System.Decimal
value.System.Decimal
value that is equivalent to the TdNumber is returned.Exception | Description |
---|---|
TdException | The TdNumber value is Null. |
System.OverflowException | The TdNumber could not be converted to a System.Decimal. |
An instance of a TdNumber will be converted into a System.Decimal
only when the number of significant digits (digits to the left of the decimal point) of the number
is less than 29. If the precision
of the number is greater than 29, the scale will be truncated so that the number will fit within the System.Decimal.
What is meant by number
is the representation of the floating decimal without the exponent. For example if an instance of TdNumber represents 2.938174e-4
, the number
is 0.00002938174
.
System.Decimal
stores numbers as a scaled integer
. It can support a number with a maximum precision of 29, maximum scale of 28, and a number in the range of minus or plus 79,228,162,514,264,337,593,543,950,335. A scaled integer
representation of a number is the number without any decimal separator. For example, the scale integer representation of 43567.90843 is 4356790843. The range of valid numbers also applies to the numbers' scaled integer representation.
Due to these characteristics of a System.Decimal, a TdNumber instance that is in the valid range may not fit into a System.Decimal unless it is truncated. These TdNumber instances will have an actual precision of 29 and a scale greater than 0. It's scaled integer representation will also be outside the valid range of the scaled integer representation of a System.Decimal
.
The following example displays two numbers that are within the range of valid System.Decimal values. However, their scale integer representation falls outside the range of the scaled integer range of the maximum System.Decimal value.
Number | Scaled Integer Representation |
---|---|
7.9228162514264337593543950336 | 79228162514264337593543950336 |
8922816251.4264337593543950335 | 89228162514264337593543950335 |
In order to perform a conversion to System.Decimal
, these numbers will be truncated one decimal place.
Number To Be Converted | Result of ToDecimal Conversion |
---|---|
7.9228162514264337593543950336 | 7.922816251426433759354395033 |
8922816251.4264337593543950335 | 8922816251.426433759354395033 |
TdNumber number; System.Decimal decimalConversion; // number = 98038.32 number = new TdNumber(0x00959838, 0, 0, 0, 0, -2); decimalConversion = TdNumber.ToDecimal(number01); Console.WriteLine("TdNumber {0} converted to System.Decimal {1}", number, decimalConversion); // number = 463748376236258608968456.45890325899806 // The System.Decimal will contain the value 463748376236258608968456.4589 number01 = new TdNumber(0x9B24EA1E, 0x9E6968B4, 0x322E08AD, 0x22E37806, 0, -14); decimalConversion = TdNumber.ToDecimal(number); Console.WriteLine(TdNumber {0} converted to System.Decimal {1}", number, decimalConversion); // The following example will throw an overflow exception because the TdNumber cannot be // adjusted to a Precision less than 29. // number = 46374837623625860896845645890325899.806 Precision = 38, Scale = 3 number = new TdNumber(0x9B24EA1E, 0x9E6968B4, 0x322E08AD, 0x22E37806, 0, -3); decimalConversion = TdNumber.ToDecimal(number);
Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019