vb.net Visual Basic 中的小数、整数和双精度数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16410573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Decimals, Integers, and Doubles in Visual Basic
提问by Deemeehaa
I'm a high school student learning coding in my pastime and I got stuck while learning Visual Basic. I'm having trouble figuring out the difference between Decimals, Doubles and Integers. I have searched the internet but found very little or confusing help. What I know so far is that Integers store whole numbers, Decimals hold's decimals and Doubles can hold both. But why would I choose Doubles over Decimals? If someone could please help explain the difference between the three.
我是一名高中生,在业余时间学习编码,但在学习 Visual Basic 时遇到了困难。我无法弄清楚小数、双精度和整数之间的区别。我在互联网上搜索过,但发现的帮助很少或令人困惑。到目前为止我所知道的是整数存储整数,小数保存小数,双精度可以保存两者。但是为什么我会选择双打而不是小数呢?如果有人可以帮助解释这三者之间的区别。
回答by Robert Harvey
Doubles are double-precision (64-bit) floating point numbers. They are represented using a 52 bit mantissa, an 11 bit exponent, and a 1 bit sign. Floating point numbers are not exact representations of decimal numbers; rather, they are binary approximations. They are therefore suitable for scientific work where precision is more important than accuracy, but are not suitable for financial calculations, where accuracy is paramount.
双精度数是双精度(64 位)浮点数。它们使用 52 位尾数、11 位指数和 1 位符号表示。浮点数不是十进制数的精确表示;相反,它们是二进制近似值。因此,它们适用于精度比准确度更重要的科学工作,但不适合精度至上的金融计算。
Decimals are the same decimal numbers we use in school, and work exactly the same way. They have a range of 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. They are as close to an exact representation of decimal numbers as possible, and are designed for financial calculations, where accuracy and minimal rounding errors are very important.
小数与我们在学校使用的十进制数相同,并且工作方式完全相同。它们的范围为 79,228,162,514,264,337,593,543,950,335 到负 79,228,162,514,264,337,593,543,950,335。它们尽可能接近十进制数的精确表示,并且专为金融计算而设计,其中准确性和最小舍入误差非常重要。
Integers are whole numbers, zero, and all of the negative representations of whole numbers. Math using integers is exact, with no round-off errors. The high-order bit represents the number's sign. Precision depends on the number of bytes used to represent the integer; for example, a 16-bit signed integer can represent numbers from -32768 to 32767.
整数是整数、零和整数的所有负表示。使用整数的数学是精确的,没有舍入错误。高位表示数字的符号。精度取决于用于表示整数的字节数;例如,一个 16 位有符号整数可以表示从 -32768 到 32767 的数字。

