Guest User

Untitled

a guest
Feb 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.math.BigDecimal;
  2. import java.math.MathContext;
  3. import java.math.RoundingMode;
  4.  
  5. public class Divide {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. MathContext mathContext = new MathContext(2, RoundingMode.DOWN);
  10.  
  11. BigDecimal numerator = new BigDecimal("0.99");
  12. BigDecimal denominator = new BigDecimal(10, mathContext);
  13.  
  14. BigDecimal result1 = numerator.divide(denominator, 2, RoundingMode.DOWN);
  15. System.out.println("Result1: "+result1);
  16.  
  17. BigDecimal result2 = numerator.divide(denominator, mathContext);
  18. System.out.println("Result2: "+result2);
  19.  
  20. numerator = new BigDecimal("0.11");
  21. denominator = new BigDecimal(10, mathContext);
  22.  
  23. result1 = numerator.divide(denominator, 2, RoundingMode.DOWN);
  24. System.out.println("Result1: "+result1);
  25.  
  26. result2 = numerator.divide(denominator, mathContext);
  27. System.out.println("Result2: "+result2);
  28.  
  29. }
  30.  
  31. }
Add Comment
Please, Sign In to add comment