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.
这篇关于转换“十进制或数字"时精度丢失/溢出的原因;数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:转换“十进制或数字"时精度丢失/溢出的原因


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01