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??
Use NormalizeDouble(). See below quotation from MQL5 reference.
Rounding floating point number to a
double value, // normalized number
int digits // number of digits after decimal point
with a floating point.
Accuracy format, number of digits after point (0-8).
Value of double type with
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().
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*/