Compartilhar via


Como: Armazenar o maior número possível em uma variável (Visual Basic)

A variable holds the largest possible numbers with precision if you declare it to be of data type Decimal. The next largest integer capacity is data type ULong. If you do not need the precision of integral data types, you can use floating-point types for even greater magnitude.

Two Different Meanings for "Largest"

Largest Precise Value. Se você precisar armazenar números inteiros grandes com precisão completa até o dígito de unidades, você pode usar o Tipo de dados decimais (Visual Basic). The Decimal type can hold integers from -79,228,162,514,264,337,593,543,950,335 through 79,228,162,514,264,337,593,543,950,335 (7.9...E+28).

Greatest Magnitude. Os tipos de fracionários Single e Double pode conter números de maior magnitude, mas não com precisão exata. The Tipo de dados único (Visual Basic) provides 8 digits of precision, and the Tipo de dados duplo (Visual Basic) provides 18 digits of precision.

To hold the largest possible integers in a variable

  1. Declare the variable with a Instrução Dim (Visual Basic).

  2. Follow the variable name with an As clause, specifying the Decimal keyword.

    Dim atomsInTheUniverse As Decimal
    

Efficient Data Types

The Decimal type has the slowest performance of all the elementary numeric data types. If your integer numbers do not attain such large values and are always positive or zero, consider the ULong type.

A variable of the Tipo de dados ULong (Visual Basic) can hold integers from 0 through 18,446,744,073,709,551,615 (1.8...E+19). Operations with ULong numbers are much faster than with Decimal, although not quite as efficient as with UInteger.

To hold large nonnegative integers in a variable with efficient performance

  1. Declare the variable with a Dim statement.

  2. Follow the variable name with an As clause, specifying the ULong keyword.

    Dim atomsInTheEarth As ULong
    

Consulte também

Referência

Resumo de tipo de dados (Visual Basic)

Tipo de Dados Inteiro (Visual Basic)

Tipo de dados Long (Visual Basic)

Tipo de dados decimais (Visual Basic)

Tipo de dados UInteger

Tipo de dados ULong (Visual Basic)

Conceitos

Caracteres de tipo (Visual Basic)

Outros recursos

Tipos de dados elementares (Visual Basic)