I want to convert the number "4,471.26"
into decimal number "4471.26"
.
Actually number "4,471.26
" is received as String and for further process, need to convert it into Decimal number.
"4,471.26"
- is just a format,so value is keeps changing every-time. This value could be anything like "654,654,25.54"
Tried by considering comma (,)
as group -separator. But looks like has different ASCII values.
String Tempholder = "4,471.26";
Decimal.valueOf(Tempholder.replaceAll(getGroupSeparator(), ""));
private char getGroupSeparator() {
DecimalFormat decFormat = new DecimalFormat();
DecimalFormatSymbols decSymbols = decFormat.getDecimalFormatSymbols();
return Character.valueOf(decSymbols.getGroupingSeparator());
}
Below code would be temporary solution, but it will not work other geo regions.
String Tempholder = "4,471.26";
Decimal.valueOf(Tempholder.replaceAll(",", ""));
Kindly help ..