MathRound

Devuelve un valor redondeado hasta el número entero más cercano del valor numérico especificado.

double  MathRound(
   double  value      // valor a redondear
   );

Parámetros

value

[in]  Valor numérico para ser redondeado.

Valor devuelto

Valor redondeado hasta el número entero más cercano.

Nota

En vez de la función MathRound() se puede usar la función round().

 

Ejemplo:

#define VALUES_TOTAL 31
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- declaramos las variables para la transformación
   double value=0;                     // número real para la transformación MathRound
   int    round_value=0;               // aquí obtenemos el resultado
//--- en un ciclo por el número de incrementos decimales de un número real
   for(int i=0i<VALUES_TOTALi++)
     {
      //--- aumentamos el valor del número real,
      //--- obtenemos un valor numérico redondeado al entero más próximo 
      //--- y mostramos en el diario de registro los valores de control
      value+=0.1;
      round_value=(int)MathRound(NormalizeDouble(value,1));
      PrintFormat("value: %.1f, round value: %d",value,round_value);
      /*
     resultado:
      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
      */
     }
  }