so i have a xml string that looks like this:
<CONFIG><Setting1><o1>44</o1><o2>1.0E-4</o2><o3>955</o3><o4>1.5E-4</o4><o5>Surname</o5></setting1>....</CONFIG>
How would i go about converting every float in a string from scientific-notion to the decimal-notation?
Edit: To clarify, im not looking to convert only a single float value from scientific to decimal nation. The String is read from a xml file that i serialized from a pojo, so all of the float values in the String would need to be converted. Sadly the XML-Framework i used (SimpleXML) only represents floats in scientific notation.
UPDATE: Tried finding the float values with RegEx, it works. "found" will be the new converted decimal. How would i go about replacing each of the the found pattern with the "found"-String?
public static void ScientificToDecimal(String text){
String found;
Pattern pattern = Pattern.compile("\\d+[.]\\d+E[+-]\\d");
Matcher matcher = pattern.matcher(text);
while(matcher.find()){
found = new BigDecimal(matcher.group()).toPlainString();
Log.i("Converted: ", matcher.group() + " to " + found);
}
}
UPDATE2: Works good enough for me.
public static String scientificToDecimal(String text){
String replacementText = "";
StringBuffer sb = new StringBuffer();
Pattern pattern = Pattern.compile("\\d+[.]\\d+E[+-]\\d");
Matcher matcher = pattern.matcher(text);
while(matcher.find()){
replacementText = new BigDecimal(matcher.group()).toPlainString();
matcher.appendReplacement(sb,replacementText);
Log.i("Converted: ", matcher.group() + " to " + replacementText);
}
matcher.appendTail(sb);
return sb.toString();
}