Tuesday, December 6, 2022

MySQL database : Double type Numeric value out of range issue

 That was a really silly mistake I made due to not reading the manual ...


I want to save numeric value with 1 decimal point . i.e. : 2.0 , 1.5 , 1.0 , 0.5 and 0.0 .

The datatype was set as double (1,1) . After test, I found out that I never able to save value bigger than or equal to 1.0  . The maximum number I saved with options (2.0 , 1.5 , 1.0 , 0.5 , 0.0) is 0.5
instead of 2.0 .

I checked through the program codes and try to figure out the error in calculation related functions.


However the answer is about the database datatype. 

Double (1,1) in MySQL never able to save number bigger than or equal to 1. 

This setting doesn't mean 1number and 1 decimal point. It means the entire number has 1 digit ONLY.

Quoted from official document as below : 

DOUBLE[(M,D)]

Here, (M,D) means that values can be stored with up to M digits in total, of which 

D digits may be after the decimal point

Double (1,1) means totally ONE digit , and ONE digit follows decimal point. The only digit is assigned decimal part , so I never able to save value before decimal point.

After I set datatype to Double (2,1) , issue resolved. 


Just a diary to remind myself to read manual .




Quoted from official : 

As of MySQL 8.0.17, the nonstandard FLOAT(M,D) and DOUBLE(M,D) syntax is deprecated and you should expect support for it to be removed in a future version of MySQL.

No comments:

Post a Comment

Something about Renpy For loop error : expected statement.

 It takes me over hour to debug. The simple fact is that under label, we cannot use For loop. One while is valid to be used under label. To ...