How to trim to i.e. 2 decimal places in the Data window? - page 6

 
Fernando Carreiro #:

Wrong! To change the number of digits in the Data windows for Inidcator Output, you have to specifically tell the Indicator the number of digits to display! You can't just use rounding or normalising. The correct solution is something like this (as mentioned in post #3):

Hey fernando, 

your solution seems exactly what i'm looking for.  I want to trim the 9 decimals showing in the window to 3 decimals. i tried : 

BBgap = 100.123456789;
BBgap = IndicatorSetInteger( INDICATOR_DIGITS, 3 );

but i'm getting a "0.0"  value showing in my screen...appreciate if you can point out what i'm doing wrong? thanks man.

 
JimSingadventure #: Hey fernando, your solution seems exactly what i'm looking for.  I want to trim the 9 decimals showing in the window to 3 decimals. i tried : but i'm getting a "0.0"  value showing in my screen...appreciate if you can point out what i'm doing wrong? thanks man.

Please read the documentation. That is not the way to use the "IndicatorSetInteger" function. That function is used to set properties of an indicator, not to adjust the digits of a variable.

ID

Description

Property type

INDICATOR_DIGITS

Accuracy of drawing of indicator values

int

Documentation on MQL5: Custom Indicators / IndicatorSetInteger
Documentation on MQL5: Custom Indicators / IndicatorSetInteger
  • www.mql5.com
IndicatorSetInteger - Custom Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Please read the documentation. That is not the way to use the "IndicatorSetInteger" function. That function is used to set properties of an indicator, not to adjust the digits of a variable.

ID

Description

Property type

INDICATOR_DIGITS

Accuracy of drawing of indicator values

int

appreciate your quick reply ferds, 

i read the documentation and from how i understand, i simply add the following under OnInit as shown below : 

void OnInit ()
{
 IndicatorSetInteger( INDICATOR_DIGITS, 3 );
}

 i just wanted to show 3-decimal values printed on my screen but the above doesnt seem to be working too as you can see the 9 decimals in my screenshot below. 

btw, i'm not trying to make any custom indicator (still newbie) but only trying to "print-variable-to-screen" with a simple comment line like so below : 

 Comment( "  "+ BBConvDivergence + "   " + DeMProc + "   " + "Alertswitch= " + (string)alertswitch +
         "  alertswitchPrevious=" + (string)alertswitchPrevious + "  " + RVIStrength + "   " + ATRStrength +
         "\nnAcceleration : " + (string)noOfLadders +  " : " + "ladderUnit : " + (string)ladderPrevious +" : " + " ...etc.);

btw, NormalizeDouble doesnt work either. The screen values actually kept on jumping up and down from the NormalizeDouble 3-decimals and then back again to the one you see above. It's very hard to read.

 
JimSingadventure #:

btw, NormalizeDouble doesnt work either. The screen values actually kept on jumping up and down from the NormalizeDouble 3-decimals and then back again to the one you see above. It's very hard to read.

Read the documentation for  NormalizeDouble, in particular

Please note that when output to Journal using the Print() function, a normalized number may contain a greater number of decimal places than you expect. For example, for:

   double a=76.671;             // A normalized number with three decimal places
   Print("Print(76.671)=",a);   // Output as is
   Print("DoubleToString(a,8)=",DoubleToString(a,8)); // Output with a preset accuracy


 

build 3194: string() function bug was fixed as I recommended.

 
Keith Watford #:

Read the documentation for  NormalizeDouble, in particular

a ZILLION thanks Keith!

it worked beautifully!

 
Jack Thomas #:

I use NormalizeDouble() quite often.

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


Example:


The output looks like this:


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

Perfect. Thanks Jack Thomas.
 
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)); }

Old post I know, but just to contribute and because I didn't see around this solution, I use

double num=1.9100000000000001;

double NormNum=(StringToDouble(DoubleToString(num,2)));
always working
 
@Daniele Nerstini #: Old post I know, but just to contribute and because I didn't see around this solution, I use always working

You solution is invalid for the question you quoted, and the answer has already been provided multiple times in post #1, #3, #11 and #52.

Please pay attention to the question and the answers already given.

Reason: