Ashish Ashish - 3 years ago 187
Java Question

How to store 3000.00 in Bigdecimal

I have tried following options.

BigDecimal expectedAmount = BigDecimal.valueOf(3000.00);


and

BigDecimal expectedAmount = BigDecimal.valueOf(3000);


and

BigDecimal expectedAmount = new BigDecimal(3000.00);


and

BigDecimal expectedAmount = new BigDecimal(3000);


All of them storing 3000.0 but I wants to store 3000.00 for my junit test. Not sure how to do it.

Answer Source

You shall use the constructor accepting the String val as:

BigDecimal expectedAmount = new BigDecimal("3000.00");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download