Change comma with dot for sub unitary values

有些话、适合烂在心里 提交于 2021-01-29 08:23:36

问题


I have a column with comma separated values such as 1,6 and 8. I tried the following code in a BigQuery and it works for 1,6 but for ,8 the result is -.8. How can I change it to 0.8 number format?

SELECT 
    column_name, 
    REPLACE(column_name,',','.') AS Price 
FROM table_name

回答1:


This is a working example to format your data based on BigQuery formatting syntax

WITH `table_name` AS (
   SELECT '1.6' as column_name UNION ALL
   SELECT '.8'
)

SELECT 
    column_name, 
    format("%g",CAST(REPLACE(column_name,',','.') AS FLOAT64)) AS Price 
FROM `table_name`

This produces the following result:



来源:https://stackoverflow.com/questions/55615070/change-comma-with-dot-for-sub-unitary-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!