views:

45

answers:

2

What is the difference between this two call? (Is there any?)

// 1.
new BigDecimal("3.53456").round(new MathContext(4, RoundingMode.HALF_UP));
// 2.
new BigDecimal("3.53456").setScale(4, RoundingMode.HALF_UP);
+2  A: 

There's no difference

dty
A: 

At least the second is faster, since there is no need for new object :) (ok, maybe setScale also create a new object inside.)

Gábor Lipták
BigDecimal is immutable. setScale() is defined to return a BigDecimal. It **might** return itself if there is no change, but if the scale is changed then it definitely will return a new object.
dty
I meant the MathContext object.
Gábor Lipták