Download MetaTrader 5

Interger (int) value in GlobalVariableSet()

To add comments, please log in or register
Wackena
648
Wackena  

I want to assign an integer (int) value to a GlobalVariable. Can an integer (int) value be modified to double value before assigned to GlobalVariableSet(), to avoid getting the data conversion warning with GlobalVariableGet() ?? If yes, How?

Paul
784
Paul  
wackena posted  :

I want to assign an integer (int) value to a GlobalVariable. Can an integer (int) value be modified to double value before assigned to GlobalVariableSet(), to avoid getting the data conversion warning with GlobalVariableGet() ?? If yes, How?

 

Assigning to a Global Variable is fine - I don't think converting up from int to double will give a conversion error because there's no potential loss of data.  To be absolutely safe about getting the correct int back, I would use MathRound (which also returns a double, something I don't understand), and also explictly typecast to int to avoid the warning.

int nGlobal=(int)MathRound(GlobalVariableGet("Global Integer"));
Wackena
648
Wackena  
phampton :

Assigning to a Global Variable is fine - I don't think converting up from int to double will give a conversion error because there's no potential loss of data.  To be absolutely safe about getting the correct int back, I would use MathRound (which also returns a double, something I don't understand), and also explictly typecast to int to avoid the warning.

Thanks very much.
To add comments, please log in or register