double numbers

 

hi

I'm working with double numbers and after I normalize them with the following formula, it still remains non-normalized and has some digits that I don't need them.

I want to know is there anyway to assure that if the double has been normalized correctly or not. I mean a formula to get the digits of the double number.

the formula to normalize:

   tick_size=MarketInfo(symbol,MODE_TICKSIZE),
   normalized_price=MathRound(price_to_normalize/tick_size)*tick_size;
 
parham.trader: it still remains non-normalized and has some digits that I don't need them.

Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
           Double-precision floating-point format - Wikipedia, the free encyclopedia

Print your variables to the accuracy you desirer.

string price_to_string(double p){ return DoubleToString(p, _Digits); }

 
whroeder1:

Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
           Double-precision floating-point format - Wikipedia, the free encyclopedia

Print your variables to the accuracy you desirer.


I want to compare 2 float number which both of them were normalized using the above-mentioned code and they supposed to be equal, but I don't know why they are not equal when I compare them. (I insist on it again that both of them were normalized before)

 
Doubles are rarely equal.
          The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum
 
whroeder1:
Doubles are rarely equal.
          The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

even if they are normalized with the stated formula ?

 
parham.trader:

even if they are normalized with the stated formula ?


Its truly strange ! because as I just re-normalized them exactly before comparing them and then the problem has been solved now ! 

The problem is just solved when I normalize them again and now they are equal!

Reason: