Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.MathContext;
- import java.math.RoundingMode;
- public class Divide {
- public static void main(String[] args) {
- MathContext mathContext = new MathContext(2, RoundingMode.DOWN);
- BigDecimal numerator = new BigDecimal("0.99");
- BigDecimal denominator = new BigDecimal(10, mathContext);
- BigDecimal result1 = numerator.divide(denominator, 2, RoundingMode.DOWN);
- System.out.println("Result1: "+result1);
- BigDecimal result2 = numerator.divide(denominator, mathContext);
- System.out.println("Result2: "+result2);
- numerator = new BigDecimal("0.11");
- denominator = new BigDecimal(10, mathContext);
- result1 = numerator.divide(denominator, 2, RoundingMode.DOWN);
- System.out.println("Result1: "+result1);
- result2 = numerator.divide(denominator, mathContext);
- System.out.println("Result2: "+result2);
- }
- }
Add Comment
Please, Sign In to add comment