Issue with StringToDouble() - page 2

 
honest_knave:

It doesn't really achieve anything beyond a simple typecast.

Like @Keith Watford I use it in conjunction with OBJ_EDIT boxes. But I opt for the simple typecast rather than the function call.

Just checked all my codes, same for me.

I am now wondering why I used StringToDouble() with CSV data .

So I made a little script to compare the speed.

2017.02.25 13:56:35.536    Bench : METHOD 1 : StringToDouble("ABCDEF") = 0.000000. Executed 10000000 times in 1078 ms.
2017.02.25 13:56:36.485    Bench : METHOD 2 : double("ABCDEF") = 0.000000. Executed 10000000 times in 953 ms.
2017.02.25 13:56:37.410    Bench : METHOD 3 : (double)"ABCDEF" = 0.000000. Executed 10000000 times in 922 ms.
2017.02.25 13:56:37.410    Bench :
2017.02.25 13:56:38.397    Bench : METHOD 1 : StringToDouble("x12345") = 0.000000. Executed 10000000 times in 984 ms.
2017.02.25 13:56:39.329    Bench : METHOD 2 : double("x12345") = 0.000000. Executed 10000000 times in 938 ms.
2017.02.25 13:56:40.273    Bench : METHOD 3 : (double)"x12345" = 0.000000. Executed 10000000 times in 937 ms.
2017.02.25 13:56:40.273    Bench :
2017.02.25 13:56:42.163    Bench : METHOD 1 : StringToDouble("123x45") = 123.000000. Executed 10000000 times in 1891 ms.
2017.02.25 13:56:43.982    Bench : METHOD 2 : double("123x45") = 123.000000. Executed 10000000 times in 1812 ms.
2017.02.25 13:56:45.746    Bench : METHOD 3 : (double)"123x45" = 123.000000. Executed 10000000 times in 1766 ms.
2017.02.25 13:56:45.746    Bench :
2017.02.25 13:56:47.923    Bench : METHOD 1 : StringToDouble("   123") = 123.000000. Executed 10000000 times in 2187 ms.
2017.02.25 13:56:50.060    Bench : METHOD 2 : double("   123") = 123.000000. Executed 10000000 times in 2125 ms.
2017.02.25 13:56:52.218    Bench : METHOD 3 : (double)"   123" = 123.000000. Executed 10000000 times in 2157 ms.
2017.02.25 13:56:52.218    Bench :
2017.02.25 13:56:54.228    Bench : METHOD 1 : StringToDouble("  12 3") = 12.000000. Executed 10000000 times in 2015 ms.
2017.02.25 13:56:56.171    Bench : METHOD 2 : double("  12 3") = 12.000000. Executed 10000000 times in 1938 ms.
2017.02.25 13:56:58.128    Bench : METHOD 3 : (double)"  12 3" = 12.000000. Executed 10000000 times in 1968 ms.
2017.02.25 13:56:58.128    Bench :
2017.02.25 13:57:01.826    Bench : METHOD 1 : StringToDouble("123.45") = 123.450000. Executed 10000000 times in 3688 ms.
2017.02.25 13:57:05.495    Bench : METHOD 2 : double("123.45") = 123.450000. Executed 10000000 times in 3672 ms.
2017.02.25 13:57:09.035    Bench : METHOD 3 : (double)"123.45" = 123.450000. Executed 10000000 times in 3547 ms.
2017.02.25 13:57:09.035    Bench :
2017.02.25 13:57:12.577    Bench : METHOD 1 : StringToDouble("123.4.5") = 123.400000. Executed 10000000 times in 3531 ms.
2017.02.25 13:57:16.122    Bench : METHOD 2 : double("123.4.5") = 123.400000. Executed 10000000 times in 3547 ms.
2017.02.25 13:57:19.626    Bench : METHOD 3 : (double)"123.4.5" = 123.400000. Executed 10000000 times in 3515 ms.
2017.02.25 13:57:19.626    Bench :
2017.02.25 13:57:21.306    Bench : METHOD 1 : StringToDouble("1,234.50") = 1.000000. Executed 10000000 times in 1672 ms.
2017.02.25 13:57:22.907    Bench : METHOD 2 : double("1,234.50") = 1.000000. Executed 10000000 times in 1610 ms.
2017.02.25 13:57:24.556    Bench : METHOD 3 : (double)"1,234.50" = 1.000000. Executed 10000000 times in 1640 ms.

 
macpee:
Thanks all for your explanation of the function StringToDouble(). But what I need now is a similar function that returns zero whenever an alphanumeric string is entered even though the string starts with a number, and returns number for a pure number. Actually, I am working with OBJ_EDIT as a text box rather than using the property window.
See this topic https://www.mql5.com/en/forum/170326
How do I check if the content of a variable is numeric?
How do I check if the content of a variable is numeric?
  • www.mql5.com
Hi, everyone. How do I check if the content of a variable is numeric, especially the content of a text box object on the chat...
 
And same test with mql5 :-D


2017.02.25 14:04:49.535    Bench :    METHOD 1 : StringToDouble("ABCDEF") = 0.000000. Executed 10000000 times in 1110 ms.
2017.02.25 14:04:51.706    Bench :    METHOD 2 : double("ABCDEF") = 0.000000. Executed 10000000 times in 2172 ms.
2017.02.25 14:04:53.556    Bench :    METHOD 3 : (double)"ABCDEF" = 0.000000. Executed 10000000 times in 1843 ms.
2017.02.25 14:04:53.556    Bench :   
2017.02.25 14:04:54.397    Bench :    METHOD 1 : StringToDouble("x12345") = 0.000000. Executed 10000000 times in 844 ms.
2017.02.25 14:04:55.208    Bench :    METHOD 2 : double("x12345") = 0.000000. Executed 10000000 times in 813 ms.
2017.02.25 14:04:55.991    Bench :    METHOD 3 : (double)"x12345" = 0.000000. Executed 10000000 times in 781 ms.
2017.02.25 14:04:55.991    Bench :   
2017.02.25 14:04:57.514    Bench :    METHOD 1 : StringToDouble("123x45") = 123.000000. Executed 10000000 times in 1515 ms.
2017.02.25 14:04:58.953    Bench :    METHOD 2 : double("123x45") = 123.000000. Executed 10000000 times in 1438 ms.
2017.02.25 14:05:00.324    Bench :    METHOD 3 : (double)"123x45" = 123.000000. Executed 10000000 times in 1375 ms.
2017.02.25 14:05:00.324    Bench :   
2017.02.25 14:05:01.851    Bench :    METHOD 1 : StringToDouble("   123") = 123.000000. Executed 10000000 times in 1531 ms.
2017.02.25 14:05:03.335    Bench :    METHOD 2 : double("   123") = 123.000000. Executed 10000000 times in 1485 ms.
2017.02.25 14:05:04.852    Bench :    METHOD 3 : (double)"   123" = 123.000000. Executed 10000000 times in 1515 ms.
2017.02.25 14:05:04.852    Bench :   
2017.02.25 14:05:06.213    Bench :    METHOD 1 : StringToDouble("  12 3") = 12.000000. Executed 10000000 times in 1360 ms.
2017.02.25 14:05:07.593    Bench :    METHOD 2 : double("  12 3") = 12.000000. Executed 10000000 times in 1375 ms.
2017.02.25 14:05:09.077    Bench :    METHOD 3 : (double)"  12 3" = 12.000000. Executed 10000000 times in 1484 ms.
2017.02.25 14:05:09.077    Bench :   
2017.02.25 14:05:11.731    Bench :    METHOD 1 : StringToDouble("123.45") = 123.450000. Executed 10000000 times in 2656 ms.
2017.02.25 14:05:14.416    Bench :    METHOD 2 : double("123.45") = 123.450000. Executed 10000000 times in 2688 ms.
2017.02.25 14:05:17.119    Bench :    METHOD 3 : (double)"123.45" = 123.450000. Executed 10000000 times in 2703 ms.
2017.02.25 14:05:17.119    Bench :   
2017.02.25 14:05:19.703    Bench :    METHOD 1 : StringToDouble("123.4.5") = 123.400000. Executed 10000000 times in 2578 ms.
2017.02.25 14:05:22.487    Bench :    METHOD 2 : double("123.4.5") = 123.400000. Executed 10000000 times in 2797 ms.
2017.02.25 14:05:25.328    Bench :    METHOD 3 : (double)"123.4.5" = 123.400000. Executed 10000000 times in 2828 ms.
2017.02.25 14:05:25.328    Bench :   
2017.02.25 14:05:26.649    Bench :    METHOD 1 : StringToDouble("1,234.50") = 1.000000. Executed 10000000 times in 1328 ms.
2017.02.25 14:05:27.953    Bench :    METHOD 2 : double("1,234.50") = 1.000000. Executed 10000000 times in 1313 ms.
2017.02.25 14:05:29.261    Bench :    METHOD 3 : (double)"1,234.50" = 1.000000. Executed 10000000 times in 1296 ms.

 
Thanks all for your explanation of the function StringToDouble(). But what I need now is a similar function that returns zero whenever an alphanumeric string is entered even though the string starts with a number, and returns number for a pure number. Actually, I am working with OBJ_EDIT as a text box rather than using the property window.






I would also appreciate it, if there is a function that removes the leading numbers and leaves only the alphabets and other symbols. So that I may execute StringToDouble on the remaining symbols (without leading numbers) and get a zero value.
 
Alain Verleyen:

So I made a little script to compare the speed.
Alain Verleyen:
And same test with mql5 :-D

Same results I had on earlier MT4 builds i.e. no change in the outcome and no consistent speed benefit from using the function call over the typecast.

So I got lazy and typed less characters from that point onwards 

 
honest_knave:

Same results I had on earlier MT4 builds i.e. no change in the outcome and no consistent speed benefit from using the function call over the typecast.

So I got lazy and typed less characters from that point onwards 

I will change all my codes to remove StringToDouble()
 
Alain Verleyen:
I will change all my codes to remove StringToDouble()
You guys may also check if the function
MathIsValidNumber()
is a solution to the leading numbers problem. It returns false if the entry is negative or positive infinity or if it is NaN (Not a number. Maybe a string etc)
 
macpee:
You guys may also check if the function
MathIsValidNumber()
is a solution to the leading numbers problem. It returns false if the entry is negative or positive infinity or if it is NaN (Not a number. Maybe a string etc)

You could check and report back.

I'm fairly sure we dealt with the MathIsValidNumber() issue in your other thread  

 
honest_knave:

You could check and report back.

I'm fairly sure we dealt with the MathIsValidNumber() issue in your other thread  

The funny thing with the function MathIsValidNumber() is that even strings are reported to be a numbers, as well as numbers. The only things that are not reported as numbers are Mathematical evaluations that have mathematical errors. It does not make any sense.
 
honest_knave:

You could check and report back.

I'm fairly sure we dealt with the MathIsValidNumber() issue in your other thread  

So we are now back to the StringToDouble() function which we discussed some days back. How would such function convert  "1st Actual" to the number 1. I need a function that will convert "1st Actual" to 0, and pure numbers to their numeric equivalence, or do you have a way around that?
Reason: