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( and M,D)DOUBLE( syntax is deprecated and you should expect support for it to be removed in a future version of MySQL.M,D)
No comments:
Post a Comment