fork 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.*;
  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. // your code goes here
  14. BigDecimal b1 = new BigDecimal("4.2597");
  15.  
  16. MathContext m = new MathContext(4); // 4 precision
  17.  
  18. // b1 is rounded using m
  19. BigDecimal b2 = b1.round(m);
  20.  
  21. // Print b2 value
  22. System.out.println("The value of " + b1 +
  23. " after rounding is " + b2);
  24. }
  25. }
Success #stdin #stdout 0.15s 51048KB
stdin
Standard input is empty
stdout
The value of 4.2597 after rounding is 4.260