MathRound

The function returns a value rounded off to the nearest integer of the specified numeric value.

double  MathRound(
   double  value      // value to be rounded
   );

Parameters

value

[in]  Numeric value before rounding.

Return Value

Value rounded till to the nearest integer.

Note

Instead of MathRound() you can use round().

 

Example:

#define VALUES_TOTAL 31
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- declare variables for conversion
   double value=0;                     // real number for MathRound conversion
   int    round_value=0;               // get the result here
//--- in a loop by the number of decimal increments of a real number
   for(int i=0i<VALUES_TOTALi++)
     {
      //--- increase the real number value,
      //--- get a numeric value rounded to the nearest integer 
      //--- and display control values in the journal
      value+=0.1;
      round_value=(int)MathRound(NormalizeDouble(value,1));
      PrintFormat("value: %.1f, round value: %d",value,round_value);
      /*
      result:
      value0.1round value0
      value0.2round value0
      value0.3round value0
      value0.4round value0
      value0.5round value1
      value0.6round value1
      value0.7round value1
      value0.8round value1
      value0.9round value1
      value1.0round value1
      value1.1round value1
      value1.2round value1
      value1.3round value1
      value1.4round value1
      value1.5round value2
      value1.6round value2
      value1.7round value2
      value1.8round value2
      value1.9round value2
      value2.0round value2
      value2.1round value2
      value2.2round value2
      value2.3round value2
      value2.4round value2
      value2.5round value3
      value2.6round value3
      value2.7round value3
      value2.8round value3
      value2.9round value3
      value3.0round value3
      value3.1round value3
      */
     }
  }