fork(1) 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.math.RoundingMode;
  7. import java.text.DecimalFormat;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. double doubleValue = 1713.6;
  15. float floatValue = 1713.6f;
  16. String fs = "%-9s : %-7s %-7s\n";
  17. System.out.printf( fs, "", "double", "float" );
  18.  
  19. DecimalFormat format = new DecimalFormat("#0");
  20. System.out.printf( fs, "toString", String.valueOf( doubleValue ), String.valueOf( floatValue ) );
  21.  
  22. format.setRoundingMode( RoundingMode.DOWN );
  23. System.out.printf( fs, "DOWN", format.format( doubleValue ), format.format( floatValue ) );
  24.  
  25. format.setRoundingMode( RoundingMode.HALF_DOWN );
  26. System.out.printf( fs, "HALF_DOWN", format.format( doubleValue ), format.format( floatValue ) );
  27.  
  28. format.setRoundingMode( RoundingMode.HALF_UP );
  29. System.out.printf( fs, "HALF_UP", format.format( doubleValue ), format.format( floatValue ) );
  30.  
  31. format.setRoundingMode( RoundingMode.UP );
  32. System.out.printf( fs, "UP", format.format( doubleValue ), format.format( floatValue ) );
  33. }
  34. }
Success #stdin #stdout 0.13s 321088KB
stdin
Standard input is empty
stdout
          : double  float  
toString  : 1713.6  1713.6 
DOWN      : 1713    1713   
HALF_DOWN : 1714    1714   
HALF_UP   : 1713    1714   
UP        : 1714    1714