为什么sum()查询返回的结果带有更多的小数点? [英] why does sum() query returns result with more decimal points?

查看:37
本文介绍了为什么sum()查询返回的结果带有更多的小数点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上图显示了我的数据库表中名为"igstAmt"的列之一.当我使用查询"SELECT sum(igstAmt)作为来自salesinvoice的igstAmt 时,它返回带有许多小数点的值 21616.7500129491 ,但是正确的答案是 21616.75 .我知道我可以在显示时将结果四舍五入,我想知道为什么会这样吗?该列中条目的最大小数点为2,因此结果也应该有2个小数点对吧,该列的数据类型为 float .

The above image shows one of the columns named 'igstAmt' in my database table. when i use the query "SELECT sum(igstAmt) as igstAmt FROM salesinvoice, it returns the value 21616.7500129491 with many decimal points, but the correct answer is 21616.75. I know I can round up the result while displaying, I want to know why is this happening like this? The maximum number of decimal points in the entries in that column is two, so the result also should have 2 decimal points, right? The datatype of the column is float.

推荐答案

float 数据类型不表示带有十进制数字的数字.它用二进制表示数字,因此数字中的二进制数字表示16,8,4,2,1,½,¼,⅛等的2的幂.

The float data type does not represent numbers with decimal digits. It represents numbers with binary, so the binary digits in the numbers represent powers of two such as 16, 8, 4, 2, 1, ½, ¼, ⅛, and so on.

显示为"272.7","0.55"等的数字不能精确表示存储的值.例如,显示为"272.7"的数字实际上可能是272.70001220703125.

The numbers shown as "272.7", "0.55", and so on are not accurate representations of the stored values. For example, the number shown as "272.7" may actually be 272.70001220703125.

用于格式化输出数字的规则可能会使用少于显示精确值所需的所有数字的数字来向您隐藏这些差异.

The rules used to format numbers for output may hide these differences from you by using fewer than all the digits needed to show the exact value.

当您添加这些数字时,实际数字与附近的十进制表示形式之间的差异可能会增大或缩小,具体取决于差异之间的机会差异.您看到的总和是这些增加的自然结果.

When you add these numbers, the differences between the actual numbers and the nearby decimal representations may grow or shrink, depending on chance variations between the differences. The sum you are seeing is a natural result of these additions.

这篇关于为什么sum()查询返回的结果带有更多的小数点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆