Bigquery SUM(Float_Values)返回多个小数位和科学记数法 [英] Bigquery SUM(Float_Values) returns multiple decimal places and Scientific Notation
问题描述
我试图计算一家商店的总销售额。我在名为UNIT_PRICE的列中有产品价格。所有的价格都有2位小数,例如:34.54或19.99等,它们在模式中作为type:float导入。 (UNIT_PRICE:float)
当我执行select查询:SELECT CompanyName,sum(Unit_Price)as sumValue等我得到以下列返回,但只有时。
2.697829165015719E7
它应该是这样的:26978291.65
当我将这些数据输出到电子表格中,然后绘制图表时,我需要它是浮点类型或至少表示正常的价格格式。
我曾尝试过以下方法,但仍有问题:
关于如何处理这个的任何想法? / p>
谢谢
BigQuery使用浮点数的默认格式,意味着根据号码的大小,可以使用科学记数法。 (请参阅%g格式说明符此处)
我们试着切换这个,但事实证明,很难获得让每个人都开心的格式。 %f格式化总是会产生十进制格式,但也会将小数点填充到6位数精度,并且将小数点以下的精度降低。
我提交了一个bug,允许在BigQuery中使用任意格式的字符串转换函数。它可以让你运行 SELECT FORMAT_STRING(%08d,SUM(Unit_Price))FROM ...
,以便能够控制输出的确切格式。 / p>
I am trying to calculate Total Sales at a store. I have product Price in a column called UNIT_PRICE. All the prices have 2 decimal places example: 34.54 or 19.99 etc and they are imported as type:float in the schema. (UNIT_PRICE:float)
When I perform the select Query: "SELECT CompanyName, SUM(Unit_Price) as sumValue" etc I get the following returned in the column, but only "sometimes".
2.697829165015719E7
It should be something like: 26978291.65
As I am piping this out into spreadsheets and then charting it I need it to be in the type float or at least represent a normal price format.
I have tried the following but still having issues:
- Source: Tried converting original data type to BigDecimal with only 2 decimal points in the source data and then exporting to the csv for import into bigquery but same result.
- Bigquery: Tried converting to a string first and then to a float and then SUM but same result. "SELECT CompanyName, SUM(Float(String(Unit_Price))) as sumValue"
Any ideas on how to deal with this?
Thanks
BigQuery uses default formatting for floating point numbers, which means that depending on the size of the number, may use scientific notation. (See the %g format specifier here)
We tried switching this, but it turns out, it is hard to get a format that makes everyone happy. %f formatting always produces decimal format, but also pads decimals to a 6 digit precision, and drops decimals beyond a certain precision.
I've filed a bug to allow an arbitrary format string conversion function in BigQuery. It would let you run SELECT FORMAT_STRING("%08d", SUM(Unit_Price)) FROM ...
in order to be able to control the exact format of the output.
这篇关于Bigquery SUM(Float_Values)返回多个小数位和科学记数法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!