3

How to write a very small number, which is approaching the limit 0? Like this:

double eps = 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001;

This is a constant, but in the code it looks terrible. Is there a shorter form?

itoctopus
  • 4,000
  • 4
  • 29
  • 44
cagounai
  • 163
  • 2
  • 8
  • http://stackoverflow.com/questions/19984040/how-to-express-numbers-in-scientific-notation-in-java – Atri Nov 15 '15 at 01:15

1 Answers1

8

Java supports scientific notation for expressing double literals. You can write a small number, say, 10-12 like this:

double eps = 1E-12;
Sergey Kalinichenko
  • 697,062
  • 78
  • 1,055
  • 1,465