在 C# 中,我应该使用什么数据类型来表示货币金额?十进制?漂浮?双倍的?我想考虑:精度、舍入等。
最佳答案
使用System.Decimal
:
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.
都不是System.Single
(float
)也不System.Double
(double
) 足够精确能够表示没有舍入误差的高精度 float 。
关于c# - 我应该使用什么数据类型来表示 C# 中的钱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1008826/