MathRound

Retourne la valeur arrondie au nombre entier le plus proche.

double  MathRound(
   double  value      // valeur à arrondir
   );

Paramètres

value

[in]  La valeur numérique à arrondir.

Valeur de Retour

La valeur arrondie au nombre entier le plus proche.

Note

On peut utiliser la fonction round() au lieu de la fonction MathRound().

 

Exemple :

#define VALUES_TOTAL 31
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- déclare les variables pour la conversion
   double value=0;                     // valeur réelle à convertir avec MathRound
   int    round_value=0;               // le résultat sera ici
//--- dans une boucle par le nombre d'incréments décimaux d'un nombre réel
   for(int i=0; i<VALUES_TOTAL; i++)
     {
      //--- augmente la valeur du nombre réel,
      //--- obtient une valeur numérique arrondie à l'entier le plus proche
      //--- et affiche les valeurs de contrôle dans le journal
      value+=0.1;
      round_value=(int)MathRound(NormalizeDouble(value,1));
      PrintFormat("value: %.1f, round value: %d",value,round_value);
      /*
     résultat :
      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
      */
     }
  }