One scenario is there in which i am reading the currencies from the webelement, and it's a string. Needed to convert it in number format for some P&L Calculation.
Tried below code
public class NumberFormat {
public static void main(String[] args) {
//String str = "$9.9967";
String str1 = "€12,32123";
String str2 = "€3.452,35";
str1 = str1.replace(",", ".").replace(".", "").replaceAll("[^0-9.]", "");
str2 = str2.replace(",", ".").replace(".", "").replaceAll("[^0-9.]", "");
double str1Ch = Double.parseDouble(str1);
double str2Ch = Double.parseDouble(str2);
System.out.println(str1Ch);
System.out.println(str2Ch);
}
}
Actual Result:
1232123.0
345235.0
Expected Result:
12.32123
3452.35
I am not getting what I am expecting, I need to perform both conversion simultaneous( dot to null/empty, comma to dot)
Need to know why code is not working and also any suggestions for reading different country currencies and converting it into number format.