Rounding numbers in MT4 via NormalizeDouble - page 12

 
lilita bogachkova:
Then you should write to Service Desk that they have invented such an extra functionMathCeil():)
It's just different, and it doesn't bother me much :)
 
Алексей Тарабанов:
int A = double B + 0.5
He is right about:"First, 0.5 is added to the fractional number and then thefractional partis cut off and the result is rounded to integer.", but MQ gave usMathCeil() to save the trouble,andMathCeil()returns the next highest integer value, not rounding
void OnStart()
  {
   ushort  Characters_delete=14;
   for(int i=0;i<=Characters_delete;i++)
     {
      double v1=i+0.999999999999999;

      int v2=v1+0.5;
      Print("v1 = ",i," = ",DoubleToString(v2,2));
     }
  }
 
Vasyl Nosal:
Five, then.
What's 5? Normalising such a number turns all 9s into zeros, so normalising and then discarding will give the wrong results.
 
lilita bogachkova:
He is right about:"First, 0.5 is added to the fractional number and thenthe fractional partis cut off from the result and the result is rounded to integer.", but MQ gave usMathCeil() not to bother with it.
Thanks, Sunny, but MathCeil only works with double: both input and output :)
 
Алексей Тарабанов:
Thanks, Sunny, but MathCeil only works with double: both input and output :)
solved: int A = (int)MathCeil(double B);
 
lilita bogachkova:
is solved: int A = (int)MathCeil(double B);
Sorry:int A =(int)MathCeil(double B+0.5)
 
Алексей Тарабанов:
Sorry:int A =(int)MathCeil(double B+0.5)
Not a:solved: int A =(int)MathCeil(double B);
 
lilita bogachkova:
Not a:solved: int A =(int)MathCeil(double B);
try: int A = MathCeil(2.6)
 
Алексей Тарабанов:
try: int A = MathCeil(2.4)

int A = MathCeil(2.4)=3

int A = MathCeil(2.4+0.5) =3

but

int A = MathCeil(2.6+0.5) =4

int A = MathCeil(2.6) =3

 
lilita bogachkova:

int A = MathCeil(2.4)=3

int A = MathCeil(2.4+0.5) =3

but

int A = MathCeil(2.6+0.5) =4

The devil is confused... 2.6, of course. The numbers are strange...