Reputation: 312
I created a table.
CREATE TABLE `test` ( `duration` double(20,5) DEFAULT NULL);
when i insert a record.
insert into test(duration) values(1.4002860713999996E8);
it is getting insert in this way.
+-----------------+
| duration |
+-----------------+
| 140028607.14000 |
where as 1.40029 is expected.Can anyone explain me the reason for this? How can i insert the exact value ?
Upvotes: 0
Views: 271
Reputation: 24144
E8
in the end means that
1.4002860713999996E8 = 1.4002860713999996 * 10^8 =
1.4002860713999996 * 100000000 = 140028607.13999996.
As soon it is double(20,5)
then MySQL performs rounding when storing value to leave only 5 digits after decimal point and we get 140028607.14000
Upvotes: 1
Reputation: 4849
The E in the 1.4002860713999996E8 is Exponent, Which means 1.40002...*10^8 , That's why you are getting the inserted value as 140028607.14000
If you want to save the exact same value, I would say use VARCHAR to store the data, and you can typecast it to double when using it, Hope it would help you.
Upvotes: 2
Reputation: 4637
It is returning the correct result as while inserting your using exponential form of data.
E8 in 1.4002860713999996E8 means 1.4002860713999996E8
into 10 to the power 8.
Upvotes: 0