Rounding numbers in MT4 via NormalizeDouble - page 11

 
Алексей Тарабанов:

And yours is wrong, I'm sorry...

Why?

void OnStart()
  {
   for(int i=1;i<=9;i++)
     {
      double v1=0.1*i;

      Print("v1 = ",v1," = ",DoubleToString(MathCeil(v1),2));
     }
  }

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.1 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.2 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.3 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.4 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.5 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.6 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.7 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.8 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.9 = 1.00

Your example:

0.1+0.5=0.6 = 1

0.2+0.5=0.7 = 1

0.3+0.5=0.8 = 1

0.4+0.5=0.9 = 1

0.5+0.5=1.0 = 1

0.6+0.5=1.1 = 1

0.7+0.5=1.2 = 1

0.8+0.5=1.3 = 1

0.9+0.5=1.4 = 1

 
lilita bogachkova:

Why?

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.1 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.2 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.3 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.4 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.5 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.6 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.7 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.8 = 1.00

0 22:49:08.463 ! tests GBPUSDbc,H1: v1 = 0.9 = 1.00

Your example:

0.1+0.5=0.6 = 1

0.2+0.5=0.7 = 1

0.3+0.5=0.8 = 1

0.4+0.5=0.9 = 1

0.5+0.5=1.0 = 1

0.6+0.5=1.1 = 1

0.7+0.5=1.2 = 1

0.8+0.5=1.3 = 1

0.9+0.5=1.4 = 1

Because the statement"int A = double B + 0.5" is solved: int A = (int)MathCeil(double B); incorrect.
 
Алексей Тарабанов:
Because the statement"int A = double B + 0.5" is solved: int A = (int)MathCeil(double B); incorrect.
So how is it solved?
 
lilita bogachkova:
So how does it get resolved?
Correct, i.e. as I said. First, 0.5 is added to the fractional number, and then the fractional part is subtracted from the result and the result is rounded to a whole number.
 
Dmitry Fedoseev:

How about this?

Then 5
 
Алексей Тарабанов:
Correct, i.e. as I said. First, 0.5 is added to the fractional number, and then the fractional part is subtracted from the result and the result is rounded to integer.
The code?
 
lilita bogachkova:
So how does it get resolved?
He can't explain. Don't disturb him.
 
Vasyl Nosal:
The code?
int A = double B + 0.5
 
Алексей Тарабанов:
Correct, i.e. as I said. First, 0.5 is added to fractional number, and then the fractional part is subtracted from the result and the result is rounded to integer.
Well, then you need to write to servicedesk, that they have invented such an extra functionMathCeil():)
 
Vasyl Nosal:
He can't explain. Don't disturb him.
Vas, don't disturb the conversation, if you please