So basically i want my float number price (eg:- 20.0) to be 20.00, with an additional zero. So what i tried to do below here is first to add an extra zero, which results in converting it to a string and then convert it back to float because my object type needs to store it as 20.00 as a Float.
Float lowest = productDetail1.getProductSummary().getPrice().getLowest();
String lowestPrice = String.format("$%.2f", lowest);
try {
Float floatVal = Float.valueOf(lowestPrice).floatValue();
productDetail1.getProductSummary().getPrice().setLowest(floatVal);
}catch (NumberFormatException e){
LOGGER.error("Number Format Exception " + e.getMessage());
}
So i debugged it, and i found out that the first 2 lines of codes work fine, but an error is thrown at line 3 :-
Float floatVal = Float.valueOf(lowestPrice).floatValue();
The error im getting is :- java.lang.numberformatexception for input string : "$10.00"
I hope someone can help me with this. A written code example will be helpful as a solution.