* characters as white space characters.
* ht - horizontal tab, nl - newline , cr - carriage return and sp - space
* trim() methods by default also takes care of these white space characters
* So trim() method is used to remove leading and trailing white spaces.
*/
XMLString s = trim();
double result = Double.NaN;
for (int i = 0; i < s.length(); i++)
{
char c = s.charAt(i);
if (c != '-' && c != '.' && ( c < 0X30 || c > 0x39)) {
// The character is not a '-' or a '.' or a digit
// then return NaN because something is wrong.
return result;
}
}
try
{
result = Double.parseDouble(s.toString());
} catch (NumberFormatException e){}
return result;
}