Download MetaTrader 5
To add comments, please log in or register
Read the Forum and improve your rating!
SI
7
SI 2014.09.05 07:23 

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 2014.09.05 07:37  
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.09.05 10:08  
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
13641
whroeder1 2014.09.05 13:32  
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