MathRound

La funzione restituisce un valore arrotondato al numero intero più vicino al valore numerico specificato.

double  MathRound(
   double  value      // valore da arrotondare
   );

Parametri

valore

[in] Valore numerico prima di arrotondare.

Valore restituito

Valore arrotondato fino al numero intero più vicino.

Nota

Invece di MathRound() è possibile utilizzare round().

 

Esempio:

#define VALUES_TOTAL 31
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- dichiarare le variabili per la conversione
   double value=0;                     // numero reale per la conversione MathRound
   int    round_value=0;               // ottenere il risultato qui
//--- in un ciclo per il numero di incrementi decimali di un numero reale
   for(int i=0i<VALUES_TOTALi++)
     {
      //--- aumentare il valore del numero reale,
      //--- ottenere un valore numerico arrotondato all'intero più vicino
 //--- e visualizzare i valori di controllo nel diario
      value+=0.1;
      round_value=(int)MathRound(NormalizeDouble(value,1));
      PrintFormat("value: %.1f, round value: %d",value,round_value);
      /*
     risultato:
      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
      */
     }
  }