Quantcast
Channel: web development helpdesk » equals
Viewing all articles
Browse latest Browse all 2

How to check two BigDecimal objects for equality?

$
0
0
Use the compareTo() method instead of the equals() method. equals() only considers two BigDecimal’s to be equal if they have same value and scale (eg. 1.25 is not equal to 1.250 when using equals() method). BigDecimal a = new BigDecimal("1.25"); BigDecimal b = new BigDecimal("1.250"); if (a.compareTo(b)==0) { System.out.println("They are equal"); }

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images