I'm trying to get a String, force it fo be a float, then format it in a way just as "###.##" (wich i can do it) and finally send it to a float variable (this is where I'm having an issue).
When I use Float.parseFloat() on that variable my float have a format "###.#" and I need the format of the float to be exactly "###.##" even if the original string is "321".
String priceLabel = "321";
float priceLabelConvertedInFloat = Float.parseFloat(priceLabel);
System.out.println(priceLabelConvertedInFloat);
NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
DecimalFormat df = (DecimalFormat)nf;
df.setMaximumFractionDigits(2);
df.setMinimumFractionDigits(2);
String priceStringWith2Decimals = df.format(priceLabelConvertedInFloat);
System.out.println(priceStringWith2Decimals);
float finalPrice = Float.parseFloat(priceStringWith2Decimals);
System.out.println(finalPrice);
It prints "321.0" -> expected / "321.00" -> expected / "321.0" -> not desired :(
Thank you for any help you can provide.