User rating: 0
Joined: Mon 12 Mar, 2012, 23:17 Posts: 6 Location: LithuaniaLithuania
Hi,
when the calendar news number comes as +3.2% or 4.54M I get error java.lang.NumberFormatException: For input string: "4.54M" .
My piece of code that works on this is: String actual = newsDetail.getActual(); double actualValue = Double.valueOf(actual.trim()).doubleValue(); // this is line that gives an error
Possibly trim does not trim letters and special signs (+,-,%, $) to get double format. How could the error be avoided? How to get number from the calendar news without special signs?
Thanks!
API Support
Post subject: Re: Numbers in calendar announcements
How to get number from the calendar news without special signs?
Consider using string operations, e.g.:
remove the % and multiply the value by 0.01,
remove the M and multiply the value by 1000000.
In fact, most probably, you would like to treat the percents and millions differently, such that such parsing could go hand-in-hand with applying different strategy logic depending on the received value type.