Download MetaTrader 5

How to do "IsNumber"?

To add comments, please log in or register
Create Forum topics and improve your rating!
sgude0
12
sgude0 2014.06.09 16:15 

Hi! I'd like test whether the OrderComment is a convertible from string to a number or not, but I can't find anything like an IsNumber() function. Is it possible to get around this?

Basically I need the code to test wehter OrderComment() is of type "1.3650" or "BALANCER" in order for the code to make better choices on what to do with that specific order.

Would appriciate any help!.


Re

Dennis

Bambang Sugianto
10224
Bambang Sugianto 2014.06.09 17:24  
StrToInteger( text ) or  StrToDouble( text )
whroeder1
14480
whroeder1 2014.06.09 18:54  
sgude0:I can't find anything like an IsNumber() function.
So make one.
Just typed, not compiled, not tested.
bool IsNumber(string s){
  for(int iPos = StringLen(s) - 1; iPos >= 0; iPos--){
     int c = StringGetCharacter(s, iPos);
     if( (c < '0' || c > '9') && c != '.') return false;
  }
  return true;
}
Just typed, not compiled, not tested.
To add comments, please log in or register