double b = StringToDouble(StringConcatenate("",balance,"")); Print(b); // Zero , Why :(What seems to be the problem here?
StringToDouble
The function converts string containing a symbol representation of number into number of double type.
double StringToDouble( string value // string ); |
Fadsel:
string balance = "12.50USD"; // lets extract the double only from the string int x = StringReplace(balance,"USD",""); // now we have a plain number Print(balance); // "12.50" double balance_only = StringToDouble(balance); Print(balance_only) ; // Zero? Why?
Your code works as it should so I don't know why you find that it doesn't.
Maybe the code that you have posted is not the code that you are using.
Hello There,
The function
always returns zero on passing a variable string. (Works when you hard code the string literally)
But Fails when passed from a variable
Let me demonstrate real quick ...
to the documentation here and here
This is supposed to work? Right? What am I missing?
Kindly Assist,
Thanks
PS: I also dropped the question here ...
https://stackoverflow.com/questions/72944645/mql4-stringtodouble-always-returns-zero
it's working very well
Before manipulating the string further,
I was also using StringSplit function i.e
StringSplit(extracted_balance_string," ", &results[]);
Instead of
StringSplit(extracted_balance_string,StringGetCharacter(" ",0), &results[]); // the space was a special character
I missed that, my bad :D
Thank you for your contributions!
- docs.mql4.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello There,
The function
StringToDouble
always returns zero on passing a variable string. (Works when you hard code the string literally)
But Fails when passed from a variable
Let me demonstrate real quick ...
to the documentation here and here
This is supposed to work? Right? What am I missing?
Kindly Assist,
Thanks
PS: I also dropped the question here ...
https://stackoverflow.com/questions/72944645/mql4-stringtodouble-always-returns-zero