Download MetaTrader 5

OrderProfit() bug

To add comments, please log in or register
SI
7
SI  

Hello guys!

 

Need some help! When using script

Profit = OrderProfit() + OrderCommission();

Comment(Profit);

 sometimes getting values like 2.100000000000001 or 2.599999999999999 instead of 2.1 and 2.6.

Basically I'm expecting to get max only 2 decimal places after point.

Even if I NormalizeDouble(Profit, 2);  still get the same. Any ideas why it happens? 

Thanks! 

qjol
3243
qjol  
Simon Gniadkowski
Moderator
18026
Simon Gniadkowski  
artwarlt:

Hello guys!

 

Need some help! When using script

Profit = OrderProfit() + OrderCommission();

Comment(Profit);

 sometimes getting values like 2.100000000000001 or 2.599999999999999 instead of 2.1 and 2.6.

Please read -->  Comment()   "Data of double type are output with the accuracy of up to 16 digits after a decimal point  . . .   To output real numbers with another accuracy or in a predefined format, use the DoubleToString() function."

All the information you need is in the documentation . . .  it's much quicker for you to read the documentation than to wait for a reply on the Forum  

whroeder1
15612
whroeder1  
artwarlt:
sometimes getting values like 2.100000000000001 or 2.599999999999999 instead of 2.1 and 2.6.
Basically I'm expecting to get max only 2 decimal places after point.
Even if I NormalizeDouble(Profit, 2); still get the same. Any ideas why it happens?
  1. A double has infinite digits after the decimal point and 0.1 can not be represented exactly. So of course you don't get exact values.
  2. Why are you expecting 2? If you printed out a price (a double) wouldn't you be expecting 4 or 5 digits? How to you expect comment/print/alert to know?
  3. NormalizeDouble returns a double. Why would you expect that to change anything? (Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong.)
To add comments, please log in or register