package org.kodejava.math;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class BigDecimalOperation {
public static void main(String[] args) {
BigDecimal decimalA = new BigDecimal("98765432123456789");
BigDecimal decimalB = new BigDecimal("10");
decimalA = decimalA.add(decimalB);
System.out.println("decimalA = " + decimalA);
decimalA = decimalA.multiply(decimalB);
System.out.println("decimalA = " + decimalA);
decimalA = decimalA.subtract(decimalB);
System.out.println("decimalA = " + decimalA);
decimalA = decimalA.divide(decimalB, RoundingMode.DOWN);
System.out.println("decimalA = " + decimalA);
decimalA = decimalA.pow(2);
System.out.println("decimalA = " + decimalA);
decimalA = decimalA.negate();
System.out.println("decimalA = " + decimalA);
}
}
Our code snippet results are:
decimalA = 98765432123456799
decimalA = 987654321234567990
decimalA = 987654321234567980
decimalA = 98765432123456798
decimalA = 9754610582533151990855052972412804
decimalA = -9754610582533151990855052972412804
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024
Obrigado!