问题描述
我目前正在 MSDN 并遇到过以下短语.
I'm currently learning "numeric" data type on MSDN and have encountered the following phrase.
从十进制或数字转换为浮点数或实数会导致一些精度损失.从 int、smallint、tinyint、float 转换,real、money 或 smallmoney 转换为十进制或数字可能会导致溢出.
Converting from decimal or numeric to float or real can cause some loss of precision. Converting from int, smallint, tinyint, float, real, money, or smallmoney to either decimal or numeric can cause overflow.
我真的不明白转换十进制或数字"数据类型时精度损失/溢出背后的原因.有人可以给我解释一下吗?
I dont really understand the reason behind loss of precision/overflow when converting "decimal or numeric" data type. Could someone please explain it to me?
推荐答案
Decimal 或 Numeric 数据类型实际上是带有小数分隔符位置的整数.关于声明的精度,它们可以存储最小值和最大值之间的每个值.正如 Ryan 所说,您可以在从 -32k 到 32k 的四个字节内存储大约 64k 个不同的值.如果你创建一个四字节的浮点类型,范围会更广,但仍然有 64k 不同的值要存储.范围内的某些值无法精确存储.
Decimal or Numeric data types are in fact integer with decimal separator position. They can store each value between min and max values, regarding declared precision. As Ryan said, you can store approx 64k different values within four bytes ranging from -32k to 32k. If you make a four bytes float type, the range would be much wider, but there are still 64k different values to be stored. Some of the values within the range are impossible to be stored precisely.
这篇关于转换“十进制或数字"时精度丢失/溢出的原因;数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!