fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.math.BigDecimal;
  4. import java.util.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. String numberAsText = "53.82233040000000557";
  14. System.out.println("as String: " + numberAsText);
  15. Double doubleValue = new Double(numberAsText);
  16. System.out.printf("as Double: %.6f\n" + doubleValue.toString());
  17.  
  18. BigDecimal decimalValue = new BigDecimal(numberAsText);
  19. System.out.println("as BigDecimal: " + decimalValue.toPlainString());
  20. }
  21. }
Runtime error #stdin #stdout #stderr 0.12s 36956KB
stdin
Standard input is empty
stdout
as     String: 53.82233040000000557
as     Double: 
stderr
Exception in thread "main" java.util.MissingFormatArgumentException: Format specifier '%.6f'
	at java.base/java.util.Formatter.format(Formatter.java:2672)
	at java.base/java.io.PrintStream.format(PrintStream.java:1053)
	at java.base/java.io.PrintStream.printf(PrintStream.java:949)
	at Ideone.main(Main.java:16)