小数VS双! - 我应该使用哪一个时? [英] decimal vs double! - Which one should I use and when?

查看:234
本文介绍了小数VS双! - 我应该使用哪一个时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直看到使用的双打在C#中的人。我知道我读的地方,双打有时会失去precision。
我的问题是,当一个应该使用双,当我应该使用十进制类型?
哪种类型适合于金钱计算的? (即超过100万$)

I keep seeing people using doubles in C#. I know I read somewhere that doubles sometimes lose precision. My question is when should a use a double and when should I use a decimal type? Which type is suitable for money computations? (ie. greater than $100 million)

推荐答案

有关金钱的总是小数。这就是为什么它被创建。

For money, always decimal. It's why it was created.

如果数字必须正确地添加或平衡,使用十进制。这包括任何金融储存或计算,分数或其他数字,人们可能会用手工做的。

If numbers must add up correctly or balance, use decimal. This includes any financial storage or calculations, scores, or other numbers that people might do by hand.

如果数字的精确值并不重要,使用双速度。这包括图形,物理或其他物理科学的计算,其中已经有一家的显著位数。

If the exact value of numbers is not important, use double for speed. This includes graphics, physics or other physical sciences computations where there is already a "number of significant digits".

这篇关于小数VS双! - 我应该使用哪一个时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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