Java BigDecimal : add method

I’ve been fooled by this stupid function twice, so I’m putting it in a memo: to add one BigDecimal to another, you have to store the add funciton output.
BigDecimal bd1 = new BigDecimal(“12.5”);
BigDecimal bd2 = new BigDecimal(“7.60”);
bd1.add(bd2); // Will not add bd2 to bd1
bd1 = bd1.add(bd2); // bd1 will contain bd1+bd2
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: