- docs.mql4.com
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:
As with most thing in life, there is more than one way to accomplish the desired results.
- www.mql5.com
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
hi i am having a problem , i get the reading of my indicator in the data window in integers like 1,2 ,-1,-2 and i need the readings to be in decimal like 1.2133 , 2.5463 soo please help me
Answer is in the post above yours - didn't you read the topic?
Had a similar issue. All methods still had some results with rounding errors so I arrived at the following: convert the number to a string and truncate.
string TruncateNumber(string number, int decimalPoints=2) { int start_index = StringFind(number, "."); if (start_index == -1) return number; string vals[2] = {"", ""}; StringSplit(number, '.', vals); if (StringLen(vals[1]) <= decimalPoints ) return number; return StringConcatenate(vals[0], ".", StringSubstr(vals[1], 0, 2)); }
Had a similar issue. All methods still had some results with rounding errors so I arrived at the following: convert the number to a string and truncate.
How is your reply relevant to the data window display digits?
source:
symb_pos_diff_lots = 0.0800000000001;
//-------
code:
symb_pos_diff_lots = (MathFloor(symb_pos_diff_lots * 100)) / 100;
symb_pos_diff_lots = NormalizeDouble(symb_pos_diff_lots, 2);
//-------
result:
symb_pos_diff_lots = 0.08;
//-------
then -> NormalizeDouble ;)
How is your reply relevant to the data window display digits?
Please read the topic before replying!
How is your reply relevant to the data window display digits?
Please read the topic before replying!
LOL... I unswer exactly to topic question -> how to trim number till 2 digits after dot!
(If MathRound or NormalizeDouble or any etc. function dont work properly on "some numbers")
I mean -> there is no difference WHERE you place your number.. you must "prepare" it before placing anywhere.. ;)
double BarVolAvg = 10694990411.760000;
BarVolAvg = (MathFloor(BarVolAvg * 100)) / 100;
BarVolAvg = NormalizeDouble(BarVolAvg, 2);
printf("BarVolAvg = " + BarVolAvg);
//-------------
BarVolAvg = 10694990411.76;
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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)); }