Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Numbers in calendar announcements
 Post subject: Numbers in calendar announcements Post rating: 0   New post Posted: Wed 21 Mar, 2012, 15:13 
User avatar

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!


 
 Post subject: Re: Numbers in calendar announcements Post rating: 0   New post Posted: Wed 21 Mar, 2012, 15:43 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
JustinasBr wrote:
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.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com