Download MetaTrader 5

Return of digits after decimal point

To add comments, please log in or register
Make screenshots in MetaTrader and manage them in the gallery!
Antoine
92
Antoine 2010.12.03 17:31 

Hello dear developers,

I would like to store in a value the Buying price of a trade but with only two digits after decimal point.

How can I do this??

Thank you.

 

Antoine. 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
Pawel Wojnarowski
685
Pawel Wojnarowski 2010.12.03 19:12  

Use NormalizeDouble(). See below quotation from MQL5 reference.

 

NormalizeDouble

Rounding floating point number to a specified accuracy.

double  NormalizeDouble(
   double  value,      // normalized number
   int     digits      // number of digits after decimal point
   );

 Parameters

value

[in] Value with a floating point.

digits

[in]  Accuracy format, number of digits after point (0-8).

Return Value

Value of double type with preset accuracy.

Note

Calculated values of StopLoss, TakeProfit, and values of open prices for pending orders must be normalized with the accuracy, the value of which can be obtained by Digits().

Example:

   double pi=M_PI;
   Print("pi = ",DoubleToString(pi,16));
      
   double pi_3=NormalizeDouble(M_PI,3);
   Print("NormalizeDouble(pi,3) = ",DoubleToString(pi_3,16))
   ;
   double pi_8=NormalizeDouble(M_PI,8);
   Print("NormalizeDouble(pi,8) = ",DoubleToString(pi_8,16));
   
   double pi_0=NormalizeDouble(M_PI,0);
   Print("NormalizeDouble(pi,0) = ",DoubleToString(pi_0,16));
/*
   Result:
   pi= 3.1415926535897931
   NormalizeDouble(pi,3)= 3.1419999999999999
   NormalizeDouble(pi,8)= 3.1415926499999998
   NormalizeDouble(pi,0)= 3.0000000000000000
*/

 

To add comments, please log in or register