# Return of digits after decimal point

92

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
683

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*/