Following are my codes to add two values
float ptoTotalAmount = 0;
Map<String, String> renewalDetailview = new LinkedHashMap<String, String>();
String Fee = driver
.findElement(
By.xpath("//div[@data-bind='html: CURRenewalFees']"))
.getText().substring(4).replace(",", "");
ptoTotalAmount += Float.valueOf((ptoFee));
String surcharge = driver
.findElement(By.xpath("//div[@data-bind='html: Surcharges']"))
.getText().substring(4).replace(",", "");
ptoTotalAmount += Float.valueOf((surcharge));
renewalDetailview.put("totalfee", Float.toString(ptoTotalAmount));
For an Example:
Fee - 31500.00,surcharge - 1500.00
Fee + surcharge = 33000.00
Thus, expected result for totalfee - 33000.00, but I'm getting 33000.0
Therefore, I applied Formatting to my float value with 2 decimal places, but I'm not getting expected result.
DecimalFormat decimalFormat = new DecimalFormat();
decimalFormat.setMinimumFractionDigits(2);
renewalDetailview.put("totalfee", String.valueOf(df.format(ptoTotalAmount)));
I'm getting 330,00 something like this, please help me to format with 2 decimal places.