c# - 我应该使用什么数据类型来表示 C# 中的钱?

标签 c#

在 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/

相关文章:

c# - WebMatrix 填充属性和 JavaScript 读取属性未产生预期结果

c# - 如何使用 JavaScriptSerializer 强制驼峰式大小写?

c# - 如何在 C# 中应用 XSLT 样式表

c# - 在finally block 中抛出异常是否是一种好的做法?

c# - 在 ASP.NET Web 窗体网站上存储和显示图像

c# - 生成链接时如何忽略当前路由值?

c# - 在 HashSet<string> 性能中搜索字符串

c# - 插入 DateTime(从 C# 到 MySQL)

c# - 尝试激活 Controller 类时接口(interface) (IOwnerRepository) 未解析

c# - 设计 : How to inform controllers about data modification across application