问题
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