Printing of large double values in JAVA with or without scientific notation
Option 1: Double d= 0.0007 ; System.out.println(d ); System.out.println(double d) Prints a long and then terminate the line. This method behaves as though it invokes print(long) and then println() . print(double d) Prints a double-precision floating-point number. The string produced by String.valueOf(double) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method. So System.out.println(double d) changes double value to String. So 0.0007 becomes 7.0E-4. Option 2: Double d= 0.000000007; System.out.println(BigDecimal.valueOf(d) ); If you use System.out.println( BigDecimal.valueOf(d)), Translates a double into a BigDecimal , using the double 's canonical string representation provided by the Double.toString(double) method. So 0.0007 is printed as 0.00070 but if the double number value is large like, d= 0.000000007 then its bec...
Comments
Post a Comment