Download MetaTrader 5

Wrong value on calculating difference in hours between TimeCurrent() and TimeLocal() - page 2

To add comments, please log in or register
whroeder1
16353
whroeder1  
wemersonrv: WHRoeder, i don't get the point with the 1800 added to the equation.
  1. How do you round a double to an int?
    int res = int(dbl + 0.5); // 0.49 + 0.50 = 0.99 -> 0
                              // 0.51 + 0.50 = 1.01 -> 1
  2. How do you round seconds to an int hours?
    int    seconds = BrokerTime - ComputerTime;
    double hours   = double(seconds) / 3600.0;
    int TimeOffset = int(hours + 0.5);
  3. How do you round a int seconds to an int hours using only integer operations?
    int seconds    = BrokerTime - ComputerTime;
    int TimeOffset = (seconds + 1800)/3600; // 0.5 * 3600 = 1800
Wemerson Guimaraes
627
Wemerson Guimaraes  
Ok, thanks!
12
To add comments, please log in or register