Rounding numbers in MT4 via NormalizeDouble - page 3

 

Mathematics. Grade 6. Textbook. Nikolsky S.M., Potapov M.K. Moscow: 2012. - 256 с

Rounding.

Rounding

 

What a heated topic this has turned out to be. MT4 seems to work correctly with rounding.
I meant forNormalizeDouble(0.055,2) not to round the number"0.055" to "0.06", but to trim it to "0.05".

I'm having trouble understanding these MKL functions. I don't really understand why "1.0015223567" should be rounded with the NormalizeDouble function, if all you want is to take the BORROWN number to the right place.
That is, to NormalizeDouble(1.001526789, 5) would result in "1.00152". It does not need
to be roundedto "1.00153". There must be the RoundDouble function for that =)

Is it possible? Or is it necessary to round it all the time and get the wrong numbers?

 

You'd better make up your mind already. It's rounding:

Forum on trading, automated trading systems and trading strategy testing

Rounding numbers in MT4 via NormalizeDouble

Roman Starinskij, 2016.01.21 10:03

Hello. Can you tell me what is the problem.

Why function NormalizeDouble(0.055,2) rounds number "0.055" to "0.06"?

It's not a fraction rounding function.


It does not:

Forum on trading, automated trading systems and strategy testing

Rounding numbers in MT4 via NormalizeDouble

Roman Starinskij, 2016.01.25 14:30

What a heated topic this has turned out to be. MT4 seems to work correctly with rounding.
I meantNormalizeDouble(0.055,2) not to round the number"0.055" to "0.06", but to trim it to "0.05".

I'm having trouble understanding these MKL functions. I don't really understand why "1.0015223567" should be rounded with the NormalizeDouble function, if all you want is to take the DIRECT number to the right place.
That is, to NormalizeDouble(1.001526789, 5) would result in "1.00152". It does not need
to be roundedto "1.00153". There must be the RoundDouble function for that =)

Is it possible? Or is it necessary to round it all the time and get numbers you don't want?


And for the sake of experimentation:

//+------------------------------------------------------------------+
//|                                              NormalizeDouble.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property script_show_inputs
#property description "Проверка NormalizeDouble"
input double   value=0.055;      // нормализуемое число 
input int      digits=2;         // кол-во знаков после запятой 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   Print("Число ",value," округлённое с точностью до ",digits," знаков = ",NormalizeDouble(value,digits));
  }
//+------------------------------------------------------------------+
Files:
Test.mq5  2 kb
 
Roman Starinskij:

What a heated topic this has turned out to be. MT4 seems to work correctly with rounding.
I meant forNormalizeDouble(0.055,2) not to round the number"0.055" to "0.06", but to trim it to "0.05".

I'm having trouble understanding these MKL functions. I don't really understand why "1.0015223567" prices should be rounded using NormalizeDouble function, if all you want is to take the DIRECT number to the right digit.
That is, to NormalizeDouble(1.001526789, 5) would result in "1.00152". It does not need
to be roundedto "1.00153". There must be the RoundDouble function for that =)

Is it possible? Or do you need to round it all the time and get numbers you don't want?

If you need to trim, then trim; if you need to round, then round. The NormalkizeDouble() function rounds and this is what you need most often.

Why do you think RoundDouble() should be used instead of NormalizeDouble()? Did you create this world? Is it OK that a ball is rolling and a square has four corners?

 
Roman Starinskij:

What a heated topic this has turned out to be.


It's all because the topic-starter doesn't read the language documentation and doesn't listen to what he's told
 
Slawa:
This is because the author does not read the language documentation and does not listen to what he is told.

The following behaviour of dividing and rounding fractions is a little unclear.

There are 2 equations:
0.06-0.02 = 0.03999999999999999
0.06-0.024 = 0.036

Using the recommended NormalizeDouble function, we get these results:
0.03999999999999999 = 0.04
0.036 = 0.04

In the first example we really need to get the value 0.04, but in the second one we need 0.03 (this is how a normal calculator works).
NormalizeDouble should be used because fractions are returned that are not complete, but in the second case, the function returns incorrect values, and you can't not use it for the first example either.

 
Roman Starinskij:

The following behaviour of dividing and rounding fractions is a little unclear.

There are two equations:
0.06-0.02 = 0.03999999999999999
0.06-0.024 = 0.036

Using the recommended NormalizeDouble function, we get these results:
0.03999999999999999 = 0.04
0.036 = 0.04

In the first example we really need to get the value 0.04, but in the second one we need 0.03 (this is how a normal calculator works).
NormalizeDouble should be used because fractions are returned that are not complete, but in the second case, the function returns incorrect values, and you can't not use it for the first example either.

Your normal calculator does not calculate correctly, it should:

 
Slawa:
All because the topicstarter does not read the language documentation and does not listen to what he is told

if N+1 digit < 5, then the Nth digit is retained and N+1 and all subsequent digits are zeroed;

if N+1 digit ≥ 5, the Nth digit is incremented by one and N+1 and all subsequent digits are zeroed;

Sorry, but I still do not understand why rounding by '2' does not immediately allow = 0.06000000

void OnStart()
  {

   double v1 = NormalizeDouble(0.055,3);
   double v2 = NormalizeDouble(0.0549,3);

   v1=NormalizeDouble(v1,2);
   v2=NormalizeDouble(v2,2);
   Print("v1 = ",DoubleToString(v1),", v2 = ",DoubleToString(v2));

  }

v1 = 0.06000000, v2 = 0.06000000

void OnStart()
  {

   double v1 = NormalizeDouble(0.055,2);
   double v2 = NormalizeDouble(0.0549,2);

   Print("v1 = ",DoubleToString(v1),", v2 = ",DoubleToString(v2));

  }

v1 = 0.06000000, v2 = 0.05000000

void OnStart()
  {
   for(int i=7;i>=1;i--)
     {
      double v1 = 1.1234567;
      double v2 = NormalizeDouble(v1,i+1);

      v1=NormalizeDouble(v1,i);
      v2=NormalizeDouble(v2,i);
      Print("v1 = ",i," = ",DoubleToString(v1,7),", v2 = ",i," = ",DoubleToString(v2,7));
     }
     Print("---");
  }

---

v1 = 1 = 1.1000000, v2 = 1 = 1.1000000
v1 = 2 = 1.1200000, v2 = 2 = 1.1200000
v1 = 3 = 1.1230000, v2 = 3 = 1.1240000
v1 = 4 = 1.1235000, v2 = 4 = 1.1235000
v1 = 5 = 1.1234600, v2 = 5 = 1.1234600
v1 = 6 = 1.1234570, v2 = 6 = 1.1234570
v1 = 7 = 1.1234567, v2 = 7 = 1.1234567




 
lilita bogachkova:


I'm sorry, but I still don't understand why rounding by '2' doesn't make it possible to get = 0.06000000


Because it's 0.6, so 0.5 can only be obtained by cheating.
 
lilita bogachkova:

I'm sorry, but I still don't understand why rounding by '2' makes it impossible to get = 0.06000000


When only one digit is normalized, it is simple: 0, 1, 2, 3, 4 -> 0, and 5, 6, 7, 8, 9 -> 1.

When two digits are normalized, two-digit numbers are taken into account: 0 - 49 -> 0, and 50 - 99 -> 1. After all, if the number 1.49 has to be rounded to integers, do we really have to get 2, which is 51 hundredths vs. the available 49 hundredths distance to 1?

Same with three-digit, four-digit, etc.