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,133
  • 4
  • 32
  • 44
cagounai
  • 155
  • 2
  • 9
  • 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
  • 714,442
  • 84
  • 1,110
  • 1,523