Carlos
Carlos

Reputation: 75

How to update a column to 2 decimals

I have a column PRICESTABLE.PRICE with values like the following

12.356898
13.587988

I need to make an update to PRICETABLE to update the prices like these:

12.350000
13.580000

Notice I don't want to ALTER the column, only round the values, thanks!

Upvotes: 0

Views: 193

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522094

The following would work for MySQL, SQL Server, and Postgres:

UPDATE PRICESTABLE
SET PRICE = ROUND(PRICE, 2);

You might want to add a WHERE clause to the above update, unless you really want to apply it to the entire table. Also, an alternative here would be to keep all the original precision, and just call ROUND when you need to present the data.

Upvotes: 2

Related Questions