StrToDouble not working

 

Can not get StrToDouble to work with a string variable as input. Definition for the function is double StrToDouble( string value) so it should work. I put this in to test it out but it always comes back zero.


string testString="This - ILTB - time";

Print("The value of StrToDouble is ", StrToDouble(StringSubstr(testString, 5, 4)));


The result is that it always comes back zero. Ive tried all kinds of different settings but StrToDouble wont accept the result from a StringSubstr as a parameter.

 
morpheus305:

Can not get StrToDouble to work with a string variable as input. Definition for the function is double StrToDouble( string value) so it should work. I put this in to test it out but it always comes back zero.


string testString="This - ILTB - time";

Print("The value of StrToDouble is ", StrToDouble(StringSubstr(testString, 5, 4)));


The result is that it always comes back zero. Ive tried all kinds of different settings but StrToDouble wont accept the result from a StringSubstr as a parameter.

Have you tried first printing out the output of your StringSubstr() call?

Looks to me like it will be "- IL".

I'm confused as to why you'd be turning that into a double.

 
cloudbreaker:

Have you tried first printing out the output of your StringSubstr() call?

Looks to me like it will be "- IL".

I'm confused as to why you'd be turning that into a double.

That was just an example. Im putting the price of the bar high in the object name at the time of the objects creation so i can go back later and search the object out and gets its value. Also i can't just the bars high value later on cause the bars final high value and the high value of the bar when the object was created could be two seperate things. The bottom line is why cant StrToDouble accept the result from a StringSubstr as a parameter. StringSubstr returns a string value which is what StrToDouble accepts as a parameter. Maybe the dev team can answer this or maybe its a bug that hasn't been addressed yet.

 

Actually you have to use this function that way:

Print("The value of StrToDouble is ", StrToDouble(StringSubstr(testString, 5, 4),5));

 
Roger:

Actually you have to use this function that way:

Print("The value of StrToDouble is ", StrToDouble(StringSubstr(testString, 5, 4),5));

Roger - you're incorrect.

Check the docs here mate.

https://docs.mql4.com/convert/StrToDouble


Works for me the way its documented. Seems the poster is using the syntax correctly, so I suggest he is supplying a string which is not meaningful as a double.

 

Yes, my fault :-(

A little mess with DoubleToStr. Sorry!!!

Reason: