Java double number problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Java double number problem

why when i do 15.7 * 3 the output is 47.0999999999944 but in regular calculator it is 47.1?

20th Oct 2017, 10:37 AM
Avi Rzayev
Avi Rzayev - avatar
2 Answers
+ 3
Floating point numbers, including doubles, are just inaccurate when stored in computers.
20th Oct 2017, 10:48 AM
LunarCoffee
LunarCoffee - avatar
+ 1
I'm guessing it's because the regular calculator did round the number, the double type is more precise on the fractals I suppose, hence the lengthy digits.
20th Oct 2017, 10:57 AM
Ipang