Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Table Adding Double Value

Tags:

mysql

I am trying to create a table on mySQL console.

CREATE TABLE TRY (Essn int(10), Pno int(2), Hours DOUBLE(40,0));

When I try to add something to table:

INSERT INTO TRY ('123456789','1','32,5');

I got an error about syntax. I couldn't find the problem. Can anyone help?

like image 647
berkc Avatar asked Mar 02 '15 16:03

berkc


People also ask

How do I create a double in MySQL?

1 Answer. “(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed.

Does Double exist in MySQL?

DOUBLE is a double precision floating point number. MySQL uses eight bytes to store a DOUBLE value. MySQL treats DOUBLE as a synonym for DOUBLE PRECISION (a non-standard extension). In addition, MySQL also treats REAL as a synonym for DOUBLE PRECISION , unless the REAL_AS_FLOAT SQL mode is enabled.

What is the difference between double and decimal in MySQL?

Double Type Some data may take more digits to the right of the decimal point. While the storage size of the decimal type is variable, the double type takes 8 bytes storage size. Also double precision ranges up to fifteen decimal digits.

What is the difference between FLOAT and double in MySQL?

Float data can hold 8 bytes, or 15 places after the decimal point. Double data is similar to float, except that it allows for much larger numbers. They're used to specify precision, that is the number of whole numbers and number of digits shown after the decimal point of a complex number.


1 Answers

Get rid of the quote, replace 32,5 with 32.5, and add VALUES keyword should work:

INSERT INTO TRY VALUES (123456789,1,32.5);

You might also want to change your double field definition for allowing more decimal numbers in Hours field:

CREATE TABLE TRY (Essn int(10), Pno int(2), Hours DOUBLE(40,2));

refer to MySQL's approximate value section for more details

“(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed. MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.

like image 114
Paul Lo Avatar answered Sep 21 '22 01:09

Paul Lo