java - Better way to parse String to Double in Android -
i trying parse currency formatted string double , string in android so:
string replaceable = string.format("[%s,.\\s]", numberformat.getcurrencyinstance().getcurrency().getsymbol()); string cleanstring = s.tostring().replaceall(replaceable, ""); double parsed = double.parsedouble(cleanstring); string formatted = numberformat.getcurrencyinstance().format((parsed/100));
i continually getting java.lang.numberformatexception: invalid double: ""
i wrapped in try catch block
double parsed = 0.00; try { parsed = double.parsedouble(cleanstring); } catch (numberformatexception e) { e.printstacktrace(); } string formatted = numberformat.getcurrencyinstance().format((parsed/100));
now works far android app no longer crashes, line of code pumps out many lines of exception wondering if there better way can parse string double , not have these many exceptions thrown because of "" character. below sample of exceptions getting
thanks time
try this:
double parsed; try { parsed = double.parsedouble(stringvalue); } catch (numberformatexception e) { parsed = 0.00; }
Comments
Post a Comment