import java.math.BigDecimal; public class Test { public static void main(String[] args) { BigDecimal num = new BigDecimal("23.56"); BigDecimal absNum = num.abs(); System.out.println("Absolute value: " + absNum); } }
Absolute value: 23.56
import java.math.BigDecimal; public class Test { public static void main(String[] args) { BigDecimal num = new BigDecimal("-17.89"); BigDecimal absNum = num.abs(); System.out.println("Absolute value: " + absNum); } }
Absolute value: 17.89The package library used in this code is java.math.