14 May 20 · npack · #Bigquery ·   Bookmark   ×

How to round up to 4 digits after decimal point in Bigquery ?

There is no Decimal datatype in BigQuery. You will have to use NUMERIC. And there is no way to specify the precision of decimals in a NUMERIC Datatype. Often we end up with values like this :

0.029*50/100=0.014500000000000002

0.0105 would have been much cleaner to read and interpret. There is a way to ROUND the decimal places in Bigquery using the ROUND() function

Select ROUND(COLUMN_NAME,4) from Mydataset.MyTable;

This will round the results to 4 decimal places. Keep in mind, the end result can be lesser than 4 digits as well:

select round(98.03001,4);

Returns: 98.03

Related Articles:

Trim and show fixed decimal places in Bigquery
Truncate decimal places in Bigquery

npack

posted on 14 May 20

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds