VB.NET最佳数据类型,用于存储货币值 [英] VB.NET best data type for storing currency values

查看:62
本文介绍了VB.NET最佳数据类型,用于存储货币值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在VB.NET中存储货币值最合适的数据类型是什么?

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

推荐答案

十进制 BCL中的System.Decimal 结构)旨在存储货币值。这是一种128位十进制浮点类型(与二进制浮点相反),对于存储高十进制精度的实际值很有用。在现实世界中,我特别指的是最初以十进制进行的测量。通常,Double适用于以十进制数字表示时不需要那么精确的计算。

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.


十进制值类型表示十进制从正数79,228,162,514,264,337,593,543,950,335到负数79,228,162,514,264,337,593,543,950,335十进制值类型适用于需要大量有效整数和小数位数且无舍入误差的财务计算。十进制类型不能消除舍入的需要。相反,它使由于舍入而产生的错误最小化。例如,以下代码产生的结果为0.99999999999999999999999999999999而不是1。

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.

这篇关于VB.NET最佳数据类型,用于存储货币值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆