Vadim Nosyrev
Vadim Nosyrev

Reputation: 113

MySQL - How do I update the decimal column to allow more digits after dot

I have this decimal(20,2) column in MySQL tables:

no  
-----
10.01
10.09
10.10
10.11
10.19
10.99

What is the easiest way to update that decimal value to

no
-------
10.001
10.009
10.010
10.011
10.099
..
10.100
10.101

If I only change column to decimal(20,3), I have 10.010, 10.020 ... 10.990

Upvotes: 0

Views: 139

Answers (1)

rbr94
rbr94

Reputation: 2287

That should work:

UPDATE TableName
SET no = no DIV 1 + MOD(no, 1) / 10

The two following functions do the following:

no DIV 1 => 10.019 DIV 1 = 10
MOD(no, 1) => MOD(10.019, 1) = 0.019

Upvotes: 2

Related Questions