0

The amount field in the ingested table is a string. Typical values will be like: £1,000.00

I would like to convert that into float. I'm using the following in the BigQuery:

SELECT SAFE_CAST(REGEXP_REPLACE('£1,000',r'(£)','') AS FLOAT64)

Then the output is: NULL

The reason for this is:

SELECT REGEXP_REPLACE('£1,000',r'(£)','')

The output is: 1,000

Because of the comma (,) in the output, it is not able to convert the value into a Float in the SAFE_CAST.

How do I remove both '£' and ',' from the string '£1,000' using REGEXP_REPLACE?

Thanks a lot.

1 Answer 1

1
SELECT SAFE_CAST(REGEXP_REPLACE('£1,000', r'[£,]', '') AS FLOAT64)
Sign up to request clarification or add additional context in comments.

1 Comment

great! consider also voting up (if not yet) :o)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.