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=0; i<VALUES_TOTAL; i++)
     {
      //--- 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:
      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
      */
     }
  }