Java BigDecimal equals() Method

The equals() method of Java BigDecimal class is used to Compare this BigDecimal with the specified Object for equality. In this method, two BigDecimal objects are found to be equal if they are equal in value and scale.

Note: 2.0 is not equal to 2.00 when compared by this method.

Syntax:

Parameter:

x: Object to which this BigDecimal is to be compared.

Exception:

No

Returns:

It returns true if and only if the specified Object is a BigDecimal whose value and scale are equal to this BigDecimal.

Example 1

Test it Now

Output:

Are these two BigDecimal objects same? : false

Example 2

Test it Now

Output:

Are these two BigDecimal objects same? : true

Example 3

Test it Now

Output:

These two BigDecimal objects are Not Same (False)

Example 4

Test it Now

Output:

These two BigDecimal objects are Same (True)

Next TopicJava BigDecimal




Latest Courses