Error in documentation or mql5 bug ?

 

According to https://www.mql5.com/en/book/common/conversions/conversions_numbers 

long StringToInteger(string text)

The function converts a string to a number of type long. Note that the result type is definitely long, and not int (despite the name) and not ulong.

An alternative way is to typecast using the operator (long). Moreover, any other integer type of your choice can be used for the cast:(int), (uint), (ulong), etc.

The conversion rules are similar to the type double, but exclude the dot character and the exponent from the allowed characters.


Following simple code does not work as documented:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Print(StringToInteger("1234"), " / ", StringToDouble("1234"));
   Print(StringToInteger("0x1234"), " / ", StringToDouble("0x1234"));
   Print(StringToInteger("0x34"), " / ", StringToDouble("0x34"));
  }
//+------------------------------------------------------------------+

MT5 build 5430 I got following as result:

1234 / 1234.0
0 / 4660.0
0 / 52.0

"Hexadecimal notation" rule does not work for StringToInteger()


MQL5 Book: Numbers to strings and vice versa / Common APIs
MQL5 Book: Numbers to strings and vice versa / Common APIs
  • www.mql5.com
Numbers to strings and back, strings to numbers, can be converted using the explicit type casting operator. For example, for types double and...