1

I tried to divided the floating point number. Finally I found the BigDecimal class, and initialized the floating point number. However it was different what I expected.

BigDecimal d1 = new BigDecimal(0.6883116883116883116883116883);
System.out.println(d1);

I expect the output will be 0.6883116883116883116883116883

but the console's output was 0.68831168831168831889755210795556195080280303955078125.

Choi
  • 483
  • 1
  • 3
  • 15
  • 1
    The double literal has already lost precision by the time it is passed to the constructor. Use the string constructor, e.g. `new BigDecimal("0.688311...")` – Michael Jul 19 '19 at 10:22
  • I tried `BigDecimal d1 = BigDecimal.valueOf(0.6883116883116883116883116883);` but it`s output was `0.6883116883116883`.. Thanks your reply. I'll try it. – Choi Jul 19 '19 at 10:27

0 Answers0