How to Get Absolute of BigDecimal Value in Java

Tags: BigDecimal

In this Java core tutorial we learn how to calculate absolute value of a java.math.BigDecimal object in Java programming language.

How to get absolute value of BigDecimal in Java

In Java, with a given BigDecimal object we can use the BigDecimal.abs() method to return absolute value of it as the following Java program.

AbsoluteBigDecimalExample1.java

import java.math.BigDecimal;

public class AbsoluteBigDecimalExample1 {
    public static void main(String... args) {
        BigDecimal bigDecimal1 = new BigDecimal("-999");
        BigDecimal bigDecimal2 = new BigDecimal("888");

        bigDecimal1 = bigDecimal1.abs();
        bigDecimal2 = bigDecimal2.abs();

        System.out.println("bigDecimal1: " + bigDecimal1);
        System.out.println("bigDecimal2: " + bigDecimal2);
    }
}
The output as below.
bigDecimal1: 999
bigDecimal2: 888

Happy Coding 😊

How to Negate BigDecimal Value in Java

How to Round BigDecimal Value in Java

Java Convert BigDecimal to BigInteger

Java Convert BigInteger to BigDecimal

Java Convert long to BigDecimal

Java Convert int to BigDecimal

Java Convert double to BigDecimal

Java Convert float to BigDecimal

How to use BigDecimal in Java by Examples

How to Add two BigDecimal values in Java

How to Subtract two BigDecimal values in Java

How to Multiply two BigDecimal values in Java

How to Divide two BigDecimal values in Java

Java Convert BigDecimal value into double value

Java Convert BigDecimal value into float value

Java Convert BigDecimal value into int value

Java Convert BigDecimal value into long value

Java Convert BigDecimal value into short value

Java Convert BigDecimal value to byte value

Java Convert BigDecimal to String

Java Convert String to BigDecimal

Java Compare two BigDecimal values