Download MetaTrader 5

How to do "IsNumber"?

To add comments, please log in or register
sgude0
12
sgude0  

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
10250
Bambang Sugianto  
StrToInteger( text ) or  StrToDouble( text )
whroeder1
14779
whroeder1  
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