十进制的区别,在.NET Float和Double? [英] Difference between Decimal, Float and Double in .NET?

查看:384
本文介绍了十进制的区别,在.NET Float和Double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

十进制浮动双击在.NET?

在会有人使用其中的一个?

When would someone use one of these?

推荐答案

浮动是的浮动的的点类型的。换句话说,他们重新present一些像这样的:

float and double are floating binary point types. In other words, they represent a number like this:

10001.10010110011

二进制数和二进制点的位置都设有连接值的范围内codeD。

The binary number and the location of the binary point are both encoded within the value.

十进制是一个浮动的十进制的点式。换句话说,他们重新present一些像这样的:

decimal is a floating decimal point type. In other words, they represent a number like this:

12345.65789

再次数和小数点的位置的点都连接值的范围内codeD - 这是什么使得十进制仍浮点类型,而不是一个固定的点类型。

Again, the number and the location of the decimal point are both encoded within the value – that's what makes decimal still a floating point type instead of a fixed point type.

要注意的重要一点是,人类被用于重新在小数形式presenting非整数,并期望在小数重presentations准确的结果;不是所有的十进制数都完全重新presentable二进制浮点 - 0.1,例如 - 因此,如果您使用的是二进制浮点值,你就会得到一个近似0.1。你仍然可以得到近似使用以及浮动小数点时 - 1除以3不可能完全重新presented,例如结果

The important thing to note is that humans are used to representing non-integers in a decimal form, and expect exact results in decimal representations; not all decimal numbers are exactly representable in binary floating point – 0.1, for example – so if you use a binary floating point value you'll actually get an approximation to 0.1. You'll still get approximations when using a floating decimal point as well – the result of dividing 1 by 3 can't be exactly represented, for example.

至于使用什么时候:

  • 有关这是自然确切小数这是很好的使用十进制值。这通常是适用于人类发明的任何概念:财务价值是最明显的例子,但也有其他人了。考虑给予潜水员或滑冰,例如得分。

  • For values which are "naturally exact decimals" it's good to use decimal. This is usually suitable for any concepts invented by humans: financial values are the most obvious example, but there are others too. Consider the score given to divers or ice skaters, for example.

有关这是自然的文物更无法真正被测量值的完全的反正浮动 / 是比较合适的。例如,科学数据通常会psented这种形式重新$ P $。在这里,原来的值将不会是小数点精确下手,所以它不是重要的了预期的效果,以保持十进制精度。二进制浮点点类型是更快的工作比小数。

For values which are more artefacts of nature which can't really be measured exactly anyway, float/double are more appropriate. For example, scientific data would usually be represented in this form. Here, the original values won't be "decimally accurate" to start with, so it's not important for the expected results to maintain the "decimal accuracy". Floating binary point types are much faster to work with than decimals.

这篇关于十进制的区别,在.NET Float和Double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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