Is it possible to use DECIMAL for DOUBLE in MySQL?

I know all the numerical values, that is, possible rounding problems inherent in floating point formats, but in my case I have DECIMAL columns in MySQL that I want to convert to DOUBLE directly in MySQL instead of flowing down.

Can anyone help?

+4
source share
3 answers

SELECT my_decimal_field + 0E0 FROM my_table

+5
source

DECIMAL can save space. For example, DECIMAL(4.2) takes up only 2 bytes. FLOAT takes 4; DOUBLE takes 8.

As for the original question, just do:

 ALTER TABLE t MODIFY COLUMN c DOUBLE ...; 

("..." should contain other material that you already had, such as NOT NULL .)

0
source

It seems impossible to pass it to DOUBLE , which brings problems if you perform calculations and, for example, want ROUND() a DECIMAL 12,2 in the third digit. Using ROUND(foo * bar,2) will simply ignore extra digits if your foo and bar are DECIMAL 12.2 fields.

Having said that, you can do something like this to still work:

 ROUND(CAST(foo AS DECIMAL(30,15)*CAST(bar AS DECIMAL(30,15)),2) 
0
source

Source: https://habr.com/ru/post/1437958/


All Articles