VB.NET best data type for storing currency values

后端 未结 1 1993
伪装坚强ぢ
伪装坚强ぢ 2021-02-20 16:08

What is the most appropriate data type for storing currency values in VB.NET?

相关标签:
1条回答
  • 2021-02-20 16:47

    Decimal (alias for System.Decimal structure in the BCL) is designed for storing monetary values. It's a 128 bit decimal floating point type (as opposed to binary floating point) and is useful for storing "real-world" values with high decimal precision. By real-world, I specifically mean measurements that are originally made in decimal. Double is generally suitable for calculations that don't need as much accuracy when they are represented as decimal numbers.

    The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. The Decimal value type is appropriate for financial calculations requiring large numbers of significant integral and fractional digits and no round-off errors. The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding. For example, the following code produces a result of 0.9999999999999999999999999999 rather than 1.

    0 讨论(0)
提交回复
热议问题