Have a table,
CREATE TABLE `double_test` (
`price` double(11,2) DEFAULT NULL
)
and there are two records:
select * from double_test;
+---------+
| price |
+---------+
| 1100.00 |
| 1396.32 |
+---------+
and sum them:
select sum(price) from double_test;
+------------+
| sum(price) |
+------------+
| 2496.32 |
+------------+
And sum the two double in Java ,
System.out.println(1100.00 + 1396.32); //2496.3199999999997
System.out.println((1100.00 + 1396.32) == 2496.32); //false
So both are double why in mysql could get correct result? and what's the difference of double type in mysql and java?
In java if use BigDecimal could get correct result, e.g.
System.out.println(BigDecimal.valueOf(1100.00).add(BigDecimal.valueOf(1396.32)).equals(BigDecimal.valueOf(2496.32)));//true
Is actually double in mysql equal to BigDecimal in Java?