-4

In my Java class. My teacher has asked this question. Can anyone help me out, I would appreciate it. TY.

why

0.3+0.3+0.3 = 0.899999999999999

in java ?????

Crisoforo Gaspar
  • 3,740
  • 2
  • 21
  • 27

1 Answers1

1

Its because of floating point precision errors. The reason is that these data types are built for fast and accurate approximations and not for exact results. For that we use BigDecimal

For more info Java Types Java Float Types

havexz
  • 9,550
  • 2
  • 33
  • 29