Not correct rounds the floating point value to the given precision

 

Hi guys,

I have this code in my indicator and I would like to get rounds the floating point values to the six digits for example -0.000092 as it is the value of the MACD indicator. The issue is that I get -0.0001. Could you help me how to fix this ?

double mMACD,mMACDSignal;
mMACD=iCustom(NULL,0,"#MTF_MACD",0,12,26,9,0,0,i);
mMACDSignal=iCustom(NULL,0,"#MTF_MACD",0,12,26,9,0,1,i);


Alert("-");
Alert("mMACD = ",mMACD," mMACDSignal = ",mMACDSignal);
Alert("-");

 

Use the new "DoubleToString" function to convert the Double into a String of the precision you require (see example below).

Alert( "mMACD = ", DoubleToString( mMACD, Digits ), " mMACDSignal = ", DoubleToString( mMACDSignal, Digits ) );

This function was previously denoted as "DoubleToStr" in the previous builds, but use the new version for forward compatibility.

MQL5 Reference: https://www.mql5.com/en/docs/convert/doubletostring

Old MQL4 Reference: https://docs.mql4.com/convert/DoubleToStr

 
FMIC:

Use the new "DoubleToString" function to convert the Double into a String of the precision you require (see example below).

This function was previously denoted as "DoubleToStr" in the previous builds, but use the new version for forward compatibility.

MQL5 Reference: https://www.mql5.com/en/docs/convert/doubletostring

Old MQL4 Reference: https://docs.mql4.com/convert/DoubleToStr


Now it is fixed. Thank you very much!
 
My pleasure! You are welcome!