import java.math.BigDecimal; public class BigDecimalExample { public static void main(String[] args) { BigDecimal num1 = new BigDecimal("12345678901234567890"); BigDecimal num2 = new BigDecimal("98765432101234567890"); BigDecimal result = num1.add(num2); System.out.println("Sum of num1 and num2 is : " + result); } }
import java.math.BigDecimal; import java.math.RoundingMode; public class BigDecimalExample { public static void main(String[] args) { BigDecimal dividend = new BigDecimal("10"); BigDecimal divisor = new BigDecimal("3"); BigDecimal result = dividend.divide(divisor, 5, RoundingMode.HALF_UP); System.out.println("Result of division is : " + result); } }In both examples, we have used the java.math.BigDecimal package library to perform calculations that involve large or precise decimal numbers. The BigDecimal class provides methods for addition, subtraction, multiplication, division, and many other mathematical operations that can be performed on decimal numbers.