Google bigquery BigQuery-四舍五入的输出有时不是真正的四舍五入

Google bigquery BigQuery-四舍五入的输出有时不是真正的四舍五入,google-bigquery,rounding,Google Bigquery,Rounding,我正在BigQuery上运行round命令,但输出并不总是像预期的那样圆。 此外,并非总是相同的值是“未舍入的” 例如,公共数据集查询: SELECT year,month,day, sum(round(weight_pounds,2))as total_pounds, count(*) as cnt FROM [bigquery-public-data:samples.natality] group by 1,2,3 order by 1,2,3 返回此输出: 黄色标记的值不是“完全四舍

我正在BigQuery上运行
round
命令,但输出并不总是像预期的那样圆。 此外,并非总是相同的值是“未舍入的”

例如,公共数据集查询:

SELECT year,month,day, sum(round(weight_pounds,2))as total_pounds, count(*) as cnt
FROM [bigquery-public-data:samples.natality] 
group by 1,2,3
order by 1,2,3
返回此输出:

黄色标记的值不是“完全四舍五入”的原因是什么? (如果我重新运行查询,其他值可能显示为.XX000001或.XX99999,但标记的值将按预期四舍五入到第二个小数点)


谢谢

我想你需要在点后四舍五入到两位数字的总和。从数学上讲,对所有数字求和,然后对结果进行四舍五入更为精确。考虑到它与未舍入的数字并不接近,你将它与什么进行比较?它应该与总和(重量磅)进行比较

非常感谢您需要运行以下查询:

SELECT 
  year,month,day, 
  round(sum(weight_pounds),2) as total_pounds, 
  sum (weight_pounds) as total_pounds1 ,
  count(*) as cnt
FROM [bigquery-public-data:samples.natality] 
group by 1,2,3
order by 1,2,3

一般来说,不能添加浮点值并获得精确的结果。