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.

Detect type of message, string or double
 Post subject: Detect type of message, string or double Post rating: 0   New post Posted: Fri 10 May, 2013, 15:46 
User avatar

User rating: 1
Joined: Sun 18 Dec, 2011, 04:05
Posts: 36
Location: Spain, Madrid
Hi,

I expect to recive double data from IMessage, but sometimes also recive String message. the question is:

-How to detect if the data is a string or double?, and if is a string, how to convert to double?

example: if recive 7,2% (string), how to convert to double 7,2.

NOTE: the error that display is: java.lang.NumberFormatException : For input string:"7,2%"

Thank you


 
 Post subject: Re: Detect type of message, string or double Post rating: 1   New post Posted: Fri 10 May, 2013, 16:24 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
It is not advised to rely on message string contents as they are subject to change, hence in such case you will need to rewrite your strategy.
However, if you still want to do it, you need to use string and double operations like:


 
 Post subject: Re: Detect type of message, string or double Post rating: 0   New post Posted: Fri 10 May, 2013, 16:43 
User avatar

User rating: 1
Joined: Sun 18 Dec, 2011, 04:05
Posts: 36
Location: Spain, Madrid
ok.

but for example on the following link https://www.dukascopy.com/wiki/#Trade_on_news.

String previous = newsDetail.getPrevious(); //get data
then
double previousValue = Double.valueOf(previous.trim()).doubleValue(); // convert data to double using valueOf

but, when recive data with % have the error.

https://www.javascripter.net/faq/convert2.htm --> posible solution?

BR


 
 Post subject: Re: Detect type of message, string or double Post rating: 0   New post Posted: Fri 10 May, 2013, 20:59 
User avatar

User rating: 1
Joined: Sun 18 Dec, 2011, 04:05
Posts: 36
Location: Spain, Madrid
Fix it.

using str.replace("","") and then convert to double

thank you


 

Jump to:  

  © 1998-2026 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