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=0; i<VALUES_TOTAL; i++)
     {
      //--- 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:
      value: 0.1, round value: 0
      value: 0.2, round value: 0
      value: 0.3, round value: 0
      value: 0.4, round value: 0
      value: 0.5, round value: 1
      value: 0.6, round value: 1
      value: 0.7, round value: 1
      value: 0.8, round value: 1
      value: 0.9, round value: 1
      value: 1.0, round value: 1
      value: 1.1, round value: 1
      value: 1.2, round value: 1
      value: 1.3, round value: 1
      value: 1.4, round value: 1
      value: 1.5, round value: 2
      value: 1.6, round value: 2
      value: 1.7, round value: 2
      value: 1.8, round value: 2
      value: 1.9, round value: 2
      value: 2.0, round value: 2
      value: 2.1, round value: 2
      value: 2.2, round value: 2
      value: 2.3, round value: 2
      value: 2.4, round value: 2
      value: 2.5, round value: 3
      value: 2.6, round value: 3
      value: 2.7, round value: 3
      value: 2.8, round value: 3
      value: 2.9, round value: 3
      value: 3.0, round value: 3
      value: 3.1, round value: 3
      */
     }
  }