2

I want to insert the value 33.55555 to database. Even after changing mysql row to float or decimal, I am unable to do so correctly.
mysql:

ALTER TABLE `test` CHANGE `test1` `test1` DECIMAL( 10,10 ) NOT NULL 

after inserting 33.55555 it is converted to 0.9999999999 via this sql command

ALTER TABLE `test` CHANGE `test1` `test1` FLOAT( 10,10 ) NOT NULL 

33.55555 is converted to 1.0000000000

0

1 Answer 1

5

Your DECIMAL() and FLOAT() declarations are off. The first parameter is how long you want the number to be, the second parameter is how many of those are decimals. So when you say FLOAT(10,10) you are saying give me a column that is 10 digits long with 10 of those digits after the decimal point.

Decimal and Float are also different in their terms of approximation. Decimals are fixed point values while floats are floating point values.

The .999999999 and 1.000000 are the maximum values for the columns.

Try this to insert 35.55555:

ALTER TABLE `test` CHANGE `test1` `test1` DECIMAL( 7,5 ) NOT NULL 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks @Blaise Swanwick. 33.55555 is a test.i want to use maximum of left and right decimal point and i want to correctly inserted to db. for example after inserting 109291.2 this is not correct 109291.2031. 031 added after inserting end of 109291.2
@TuxWorld dev.mysql.com/doc/refman/5.1/en/fixed-point-types.html Contains some reading. The maximum amt of data you can store in a decimal field is beyond my knowledge. But I do know I would rather use a decimal field over a float field if I needed precision.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.