One could argue that it is more readable to use valueOf(x)
than "" + x
. Internally, both will fall back to toString
but they can also deal with null values (where null.toString()
will throw a NullPointerException
).
In theory, the performance of valueOf(x)
should be better than "" + x
, as the latter uses a StringBuilder
internally, which can lead to some overhead.
When you know that your BigDecimal
is non-null (as in your example), you should just use toString
.
By the way, be careful with the BigDecimal(double)
constructor. The safer approach is to use
new BigDecimal("12.3434379328948927894789237")
in your example. The reason why BigDecimal(double)
is unpredicable is explained in its Javadoc comment.