Download MetaTrader 5

How to trim to i.e. 2 decimal places

To add comments, please log in or register
selnomeria
254
selnomeria  

in Indicator Data window,the numbers (after dot) show bunch of zeroes:

i need to be shown there only 2 decimals after dot.


used this function, but still doesnt help, there are still ZEROes shown...


double RoundNumber(double number, int digits) {  number = MathRound(number * MathPow(10, digits));  return (number * MathPow(10, -digits)); }


honest_knave
Moderator
2296
honest_knave  
IndicatorDigits - Custom Indicators - MQL4 Reference
IndicatorDigits - Custom Indicators - MQL4 Reference
  • docs.mql4.com
IndicatorDigits - Custom Indicators - MQL4 Reference
Jack Thomas
2163
Jack Thomas  

I use NormalizeDouble() quite often.

https://www.mql5.com/en/docs/convert/normalizedouble


Example:

double something = 0.123456789;
double someother = NormalizeDouble(something,2);
Comment("Something = "+(string)something+"\nSomeother: "+(string)someother);


The output looks like this:

Round double to 2 digit precision.


As with most thing in life, there is more than one way to accomplish the desired results.

Documentation on MQL5: Conversion Functions / NormalizeDouble
Documentation on MQL5: Conversion Functions / NormalizeDouble
  • www.mql5.com
Conversion Functions / NormalizeDouble - Reference on algorithmic/automated trading language for MetaTrader 5
honest_knave
Moderator
2296
honest_knave  

Both those methods (MathRound and NormalizeDouble) do not change the output of the data window. For that, you have to use IndicatorDigits() for MQL4 or IndicatorSetInteger(INDICATOR_DIGITS,x) for both MQL4 and MQL5

To add comments, please log in or register