## Thursday, October 30, 2014

The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can represent values in excess of 7.9228 x 10^28. It is particularly suitable for calculations, such as financial, that require a large number of digits but cannot tolerate rounding errors.

### Dim d1, d2, d3, d4 As Decimal  d1 = 2.375D d2 = 1.625D  d3 = d1 + d2 d4 = 4.000D MsgBox("d1 = " & CStr(d1) & ", d2 = " & CStr(d2) &  ", d3 = " & CStr(d3) & ", d4 = " & CStr(d4) The output of MsgBox in the preceding example is as follows: d1 = 2.375, d2 = 1.625, d3 = 4.000, d4 = 4

Type Characters. Appending the literal type character D to a literal forces it to the Decimal data type. Appending the identifier type character @ to any identifier forces it to Decimal.
Framework Type. The corresponding type in the .NET Framework is the System.Decimal structure.

### Range

You might need to use the D type character to assign a large value to a Decimal variable or constant. This requirement is because the compiler interprets a literal as Longunless a literal type character follows the literal, as the following example shows.
`Dim bigDec1 As Decimal = 9223372036854775807   ' No overflow.`
`Dim bigDec2 As Decimal = 9223372036854775808   ' Overflow.`
`Dim bigDec3 As Decimal = 9223372036854775808D  ' No overflow.`
The declaration for bigDec1 doesn't produce an overflow because the value that's assigned to it falls within the range for Long. The Long value can be assigned to the Decimalvariable.
The declaration for bigDec2 generates an overflow error because the value that's assigned to it is too large for Long. Because the numeric literal can't first be interpreted as aLong, it can't be assigned to the Decimal variable.

For bigDec3, the literal type character D solves the problem by forcing the compiler to interpret the literal as a Decimal instead of as a Long.