the reason behind loss of precision/overflow when converting quot;decimal or numericquot; data type(转换“十进制或数字时精度丢失/溢出的原因;数据类型)
问题描述
我目前正在 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.
这篇关于转换“十进制或数字"时精度丢失/溢出的原因;数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:转换“十进制或数字"时精度丢失/溢出的原因


- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01