fork(14) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.text.DecimalFormat;
  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. double a = 91.32;
  14. double b = 5.22;
  15. double c = 11.5;
  16. double d = 1.2;
  17. double e = 2.6;
  18.  
  19. System.out.println(getTwoDecimals(a));
  20. System.out.println(getTwoDecimals(b));
  21. System.out.println(getTwoDecimals(c));
  22. System.out.println(getTwoDecimals(d));
  23. System.out.println(getTwoDecimals(e));
  24.  
  25. }
  26.  
  27. private static String getTwoDecimals(double value){
  28. DecimalFormat df = new DecimalFormat("0.00");
  29. return df.format(value);
  30. }
  31.  
  32. }
Success #stdin #stdout 0.12s 29032KB
stdin
Standard input is empty
stdout
91.32
5.22
11.50
1.20
2.60