我目前正在 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.
这篇关于转换“十进制或数字"时精度丢失/溢出的原因;数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
修改现有小数位信息Modify Existing decimal places info(修改现有小数位信息)
多次指定相关名称“CONVERT"The correlation name #39;CONVERT#39; is specified multiple times(多次指定相关名称“CONVERT)
T-SQL 左连接不返回空列T-SQL left join not returning null columns(T-SQL 左连接不返回空列)
从逗号或管道运算符字符串中删除重复项remove duplicates from comma or pipeline operator string(从逗号或管道运算符字符串中删除重复项)
将迭代查询更改为基于关系集的查询Change an iterative query to a relational set-based query(将迭代查询更改为基于关系集的查询)
将零连接到 sql server 选择值仍然显示 4 位而不是concatenate a zero onto sql server select value shows 4 digits still and not 5(将零连接到 sql server 选择值仍然显示 4 位而不是 5)