Поделиться через


Single Data Type (Visual Basic)

Holds signed IEEE 32-bit (4-byte) single-precision floating-point numbers ranging in value from -3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values. Single-precision numbers store an approximation of a real number.

Remarks

Use the Single data type to contain floating-point values that do not require the full data width of Double. In some cases the common language runtime might be able to pack your Single variables closely together and save memory consumption.

The default value of Single is 0.

Programming Tips

  • Precision. When you work with floating-point numbers, keep in mind that they do not always have a precise representation in memory. This could lead to unexpected results from certain operations, such as value comparison and the Mod operator. For more information, see Troubleshooting Data Types (Visual Basic).

  • Widening. The Single data type widens to Double. This means you can convert Single to Double without encountering a System.OverflowException error.

  • Trailing Zeros. The floating-point data types do not have any internal representation of trailing 0 characters. For example, they do not distinguish between 4.2000 and 4.2. Consequently, trailing 0 characters do not appear when you display or print floating-point values.

  • Type Characters. Appending the literal type character F to a literal forces it to the Single data type. Appending the identifier type character ! to any identifier forces it to Single.

  • Framework Type. The corresponding type in the .NET Framework is the System.Single structure.

See Also

Tasks

Troubleshooting Data Types (Visual Basic)

Reference

Data Type Summary (Visual Basic)

System.Single

Decimal Data Type (Visual Basic)

Double Data Type (Visual Basic)

Type Conversion Functions (Visual Basic)

Conversion Summary (Visual Basic)

Concepts

Efficient Use of Data Types (Visual Basic)