Arda Balkan
Arda Balkan

Reputation: 43

Round Decimals and Update in same MySQL Table

I have an MySQL table like this:
-------------------------------------------
|ID | Name | Value |
| 1 | Jack | 1.0382948092380932980293 |
| 2 | John | 12.3489245802843509384001 |
| 3 | Bill | 6.0293892838236487263872 |
-------------------------------------------

I want to update Values to three-digit decimal number after the comma like the scheme below.
------------------------
|ID | Name | Value |
| 1 | Jack | 1.038 |
| 2 | John | 12.348 |
| 3 | Bill | 6.029 |
------------------------

How can I do this using MySQL sentence? Thank you.

Upvotes: 4

Views: 7088

Answers (2)

风声猎猎
风声猎猎

Reputation: 1201

You want to round up the value use jherran answer, But I think you want to round down the value, so you should use: truncate function

update tablename set fieldname = truncate(fieldname ,3) 

refer to : https://stackoverflow.com/a/69548823

Upvotes: 0

jherran
jherran

Reputation: 3367

You need to use round:

update tablename set fieldname = round(fieldname,3) 

Upvotes: 5

Related Questions