如何使用bigquery将结果四舍五入到小数点后4位? [英] How to use bigquery round up results to 4 digits after decimal point?

查看:224
本文介绍了如何使用bigquery将结果四舍五入到小数点后4位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们现在在BigQuery中没有十进制数据类型.所以我必须使用float

We don't have decimal data type in BigQuery now. So I have to use float

但是

在Bigquery浮点运算中

In Bigquery float division

0.029 * 50/100 = 0.014500000000000002

0.029*50/100=0.014500000000000002

尽管

0.021 * 50/100 = 0.0105

0.021*50/100=0.0105

将值四舍五入

我必须使用round(floatvalue * 10000)/10000.

I have to use round(floatvalue*10000)/10000.

这是现在BigQuery中处理十进制数据类型的正确方法吗?

Is this the right way to deal with decimal data type now in BigQuery?

推荐答案

请注意,这个问题现在应该得到不同的答案.

Note that this question deserves a different answer now.

问题的前提是我们现在在BigQuery中没有十进制数据类型."

The premise of the question is "We don't have decimal data type in BigQuery now."

但是现在我们要做:您可以使用NUMERIC:

But now we do: You can use NUMERIC:

SELECT CAST('0.029' AS NUMERIC)*50/100

# 0.0145

只需将您的列设置为NUMERIC而不是FLOAT64,即可获得所需的结果.

Just make your column is NUMERIC instead of FLOAT64, and you'll get the desired results.

这篇关于如何使用bigquery将结果四舍五入到小数点后4位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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