我应该使用什么数据类型在C#中重新present钱? [英] What data type should I use to represent money in C#?

查看:94
本文介绍了我应该使用什么数据类型在C#中重新present钱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我应该用什么数据类型来重新present货币金额?十进制?浮动?双?我要好好考虑:precision,四舍五入等

In C#, what data type should I use to represent monetary amounts? Decimal? Float? Double? I want to take in consideration: precision, rounding, etc.

推荐答案

使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.decimal.aspx\"><$c$c>System.Decimal:

十进制值类型重新presents
  十进制数从正面
  79,228,162,514,264,337,593,543,950,335
  至负面
  79,228,162,514,264,337,593,543,950,335。
   十进制值类型是合适的
  对于需要财务计算
  大量显著积分
  和小数位且没有舍入
  错误。
十进制类型不
  消除了舍入的需要。
  相反,它最大限度地减少由于错误
  四舍五入。

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 浮动)也不 System.Double 双击 precise足够能够重新$的p $ psenting高precision浮点数没有舍入误差。

Neither System.Single (float) nor System.Double (double) are precise enough capable of representing high-precision floating point numbers without rounding errors.

这篇关于我应该使用什么数据类型在C#中重新present钱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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