Use new BigDecimal(string)
. This will guarantee proper calculation later.
As a rule of thumb - always use BigDecimal
for sensitive calculations like money.
Example:
String doubleAsString = "23.23";
BigDecimal price = new BigDecimal(doubleAsString);
BigDecimal total = price.plus(anotherPrice);