How many significant digits should I use for double literals in Java?

Posted by M. Dudley on Stack Overflow See other posts from Stack Overflow or by M. Dudley
Published on 2013-11-04T15:41:01Z Indexed on 2013/11/04 15:53 UTC
Read the original article Hit count: 308

Filed under:
|
|

How many significant digits should I use when defining a double literal in Java? This is assuming that I am trying to represent a number with more significant figures than a double can hold.

In Math.java I see 20 and 21:

public static final double E = 2.7182818284590452354;
public static final double PI = 3.14159265358979323846;

This is more than the 15-17 significant digits provided by IEEE 754. So what's the general rule-of-thumb?

© Stack Overflow or respective owner

Related posts about java

Related posts about literals