Parameters
- input
- The TdDecimal that is to be converted to a
System.Decimalvalue.
Return Value
System.Decimal value that is equivalent to the TdDecimal is returned.System.Decimal value.
System.Decimal value.System.Decimal value that is equivalent to the TdDecimal is returned.| Exception | Description |
|---|---|
| TdException | The TdDecimal value is Null. |
| System.OverflowException | The TdDecimal could not be converted to a System.Decimal |
System.Decimal it will be converted into a System.Decimal if the TdDecimal can be adjusted so the following are true:
actual precision of the number will be less than or equal to the maximum precision of System.Decimal.
Scale will be less than or equal to the maximum scale of System.DecimalSystem.Decimal will be truncated.
The actual precision refers to the precision of the number contained in the TdDecimal structure, not the precision that was specified when creating the TdDecimal. For example, the number 3.8432 has an actual precision of 5 and a scale of 4. A TdDecimal can be initialized with this number with a precision defined as 38 and a scale of 4 using the constructor:
new TdDecimal(38432, 0, 0, 0, 38, 4)
System.Decimal stores numbers as a scaled integer. It can support a number with a maximum precision of 29, maximum scale of 28, and 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, numbers that have valid precision/scale and are in the valid range may not fit into a System.Decimal. They will need to be truncated one decimal place. These numbers will have an actual precision of 29 and a scale greater than 0. These numbers will also have a scaled integer representation outside the valid range of a System.Decimal. The following are examples of some of these numbers:
| 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 |
| 7922816251426433759354959678.5 | 7922816251426433759354959678 |
| 9922816251426433759354395033.2 | 9922816251426433759354395033 |
TdDecimal number;
System.Decimal decimalConversion;
// number = 98038.32 Precision = 7, Scale = 2
number = new TdDecimal(0x00959838, 0, 0, 0, 7, 2);
decimalConversion = TdDecimal.ToDecimal(number01);
Console.WriteLine("TdDecimal {0} converted to System.Decimal {1}", number, decimalConversion);
// number = 463748376236258608968456.45890325899806 Precision = 38, Scale = 14
// The System.Decimal will contain the value 463748376236258608968456.4589
number01 = new TdDecimal(0x9B24EA1E, 0x9E6968B4, 0x322E08AD, 0x22E37806, 38, 14);
decimalConversion = TdDecimal.ToDecimal(number);
Console.WriteLine(TdDecimal {0} converted to System.Decimal {1}", number, decimalConversion);
// The following example will throw an overflow exception because the TdDecimal cannot be
// adjusted to a Precision less than 29.
// number = 46374837623625860896845645890325899.806 Precision = 38, Scale = 3
number = new TdDecimal(0x9B24EA1E, 0x9E6968B4, 0x322E08AD, 0x22E37806, 38, 3);
decimalConversion = TdDecimal.ToDecimal(number);Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019