Rounding numbers in MT4 via NormalizeDouble - page 13

 
Алексей Тарабанов:
The devil is in the mix... 2.6, of course.
it's time for bed.
 
lilita bogachkova:
It's time for bed.
Joining
 
Dmitry Fedoseev:
What's 5? Normalising such a number turns all 9's into zeros, so normalising and then discarding would give wrong results.
DoubleToString(0.99999,5)
 
Vasyl Nosal:
DoubleToString(0.99999,5)

Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So we normalize it to three digits, get 1.000, discard one, and get 1.00, but not 0.99.

 
Dmitry Fedoseev:

Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So we normalize it to three digits, get 1.000, discard one, and get 1.00, but not 0.99.

extern ushort Characters_delete = 3;

///////////////////////////////////////////
string data=DoubleToString(0.99999,5); 
string resoult=StringSubstr(data,0,StringLen(data)-Characters_delete);
 
Vasyl Nosal:
Yeah... and suddenly we have the number 0.999999 instead of 0.999999.
 
Dmitry Fedoseev:
Yeah... and suddenly we have the number 0.999999 instead of 0.999999.
string(0.999999)
 
It reminds me of the anecdote about the missing programmer. And he is sitting in a cold bath, shampoo in his hands with the instructions "soap, rinse, repeat".
 
Dmitry Fedoseev:
It reminds me of a joke about a programmer who has gone missing. He was sitting in a cold bath, shampoo in his hands with the instruction "soap, rinse and repeat".
Why does a language need such precision: that the number (for example) "0.7" is actually stored as "0.69999..."?
Is this actually used somewhere? I'm used to counting numbers like in a calculator, it shows accurately.
Yes, perhaps the calculator itself rounds something, and doesn't store the exact numbers itself...
Who needs to use such approximate figures with infinite fractions instead of exact values?
Divide it, get 0.7 and don't bother with cropping or rounding :-)
 
Dmitry Fedoseev:

Well, what if the number is 0.99999 and you have to leave two digits? Discard the rest. We need to get 0.99. So, according to the algorithm suggested above, normalize to three digits, we get 1.000, discard one and get 1.00, but not 0.99.

try to get a result of0.99999999999999999

X = 0.99999999999999999

10*X = 10*0.99999999999999999

10*X-X = 10*0.999999999999999-0.9999999999999

9*X = 9*0.99999999999999999

we get 9*X = 9 or X equals 1 (one)

void OnStart()
  {
      double v1=1.0/3.0;
      double v2=3.0*v1;

      Print("v1 = (1/3) = ",DoubleToString(v1)," | ","v2 = 3*(1/3) = ",DoubleToString(v2));
  }

v1 = (1/3) = 0.33333333 | v2 = 3*(1/3) = 1.00000000

or 0.999999999999999 = 1.0

void OnStart()
  {
      double v1=0.99999999999999999;

      if(v1>=1.0)
         Print("v1 (",DoubleToString(v1),") >= 1.0");
  }

v1 (1.00000000) >= 1.0