Tipo de dados decimais (Visual Basic)
Suspensões assinado 128-bits (16byte) valores que representam 96-bits (12 -byte) números inteiro dimensionado por uma potência variável de 10. O fator de escala Especifica o número de dígitos à direita do ponto decimal ; ele varia de 0 a 28. Com uma escala de 0 (sem casas decimal ), o maior valor possível é + /-79.228.162.514.264.337.593.543.950.335 (+ /-7 .9228162514264337593543950335e + 28). With 28 decimal places, the largest value is +/-7.9228162514264337593543950335, and the smallest nonzero value is +/-0.0000000000000000000000000001 (+/-1E-28).
Comentários
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.
The default value of Decimal is 0.
Programming Tips
Precision. Decimal is not a floating-point data type. The Decimal structure holds a binary integer value, together with a sign bit and an integer scaling factor that specifies what portion of the value is a decimal fraction. Because of this, Decimal numbers have a more precise representation in memory than floating-point types (Single and Double).
Desempenho. O Decimal tipo de dados é o mais lento de todos os tipos numéricos. You should weigh the importance of precision against performance before choosing a data type.
Alargamento. O Decimal tipo de dados amplia a Single ou Double. This means you can convert Decimal to either of these types without encountering a System.OverflowException error.
Trailing Zeros. Visual Basic não armazena os zeros à direita em uma Decimal literal. However, a Decimal variable preserves any trailing zeros acquired computationally. The following example illustrates this.
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
Tipo Caracteres. Acrescentando o caractere de tipo literal D para um literal de força para o Decimal tipo de dados. Appending the identifier type character @ to any identifier forces it to Decimal.
Framework Type. O tipo correspondente na.NET Framework é o System.Decimal estrutura.
Range
You might need to use the D type character to assign a large value to a Decimal variable or constant. The following example illustrates this.
Dim bigDec1 As Decimal = 9223372036854775807 ' No overflow.
Dim bigDec2 As Decimal = 9223372036854775808 ' Overflow.
Dim bigDec3 As Decimal = 9223372036854775808D ' No overflow.
The compiler interprets a literal as Long unless it is followed by a literal type character. The declaration for bigDec1 does not produce an overflow because its value is within the range for Long. However, the value for bigDec2 is too large for Long, so the compiler generates an error. The literal type character D solves the problem for bigDec3 by forcing the compiler to interpret the literal as Decimal.
Consulte também
Referência
Resumo de tipo de dados (Visual Basic)
Decimal.Decimal
Tipo de dados único (Visual Basic)
Tipo de dados duplo (Visual Basic)
Funções de conversão de tipo (Visual Basic)
Resumo de conversão (Visual Basic)