Download MetaTrader 5

StrinFormate, double and initial zeros..

To add comments, please log in or register
Publish your application in Cobe Base. Millions of traders will see it!
Carl Schreiber
6588
Carl Schreiber 2016.11.09 20:38 

Is it true that I cannot define e.g. for Comment(..) leading zeros  before the decimal point.

As I want to show percent-numbers which range from 1.1% to 999.9% and I want to be able to

see mat the chart (with Comment(..)) 001.1% .. 009.9 % .. 022.2 % .. 123.4 % .. 999.9 %.

I tried StringFormat(%03.5f) => a) 3 numbers before '.',  b) the '.' and  c) 1 decimal = 5 char.

(I remember this from c somehow) but this isn't working.

Anything else ( but not if (x>100).. else if(>9.9) .. else ...  I don't like this operating expense for just a simple print to screen).

honest_knave
Moderator
2199
honest_knave 2016.11.09 20:52  
Carl Schreiber:

Is it true that I cannot define e.g. for Comment(..) leading zeros  before the decimal point.

As I want to show percent-numbers which range from 1.1% to 999.9% and I want to be able to

see mat the chart (with Comment(..)) 001.1% .. 009.9 % .. 022.2 % .. 123.4 % .. 999.9 %.

I tried StringFormat(%03.5f) => a) 3 numbers before '.',  b) the '.' and  c) 1 decimal = 5 char.

(I remember this from c somehow) but this isn't working.

Anything else ( but not if (x>100).. else if(>9.9) .. else ...  I don't like this operating expense for just a simple print to screen).

   double Per1=1.1,
          Per2=22.2,
          Per3=333.3;
   Comment(StringFormat("%5.1f%%\n%5.1f%%\n%5.1f%%",Per1,Per2,Per3));
Change %5.1f to %05.1f if you want the leading zeros (rather than blank spaces)
Carl Schreiber
6588
Carl Schreiber 2016.11.09 21:06  

Exactly this I tried in mt4 and it does not work :(


Just look at the number in brackets 70.1% and 108.1% neither leading zeros nor leading blanks.  :(

whroeder1
14497
whroeder1 2016.11.09 21:18  
Carl Schreiber: I tried StringFormat(%03.5f) => a) 3 numbers before '.',  b) the '.' and  c) 1 decimal = 5 char. (I remember this from c somehow) but this isn't working.

PrintFormat - Common Functions - MQL4 Reference

%[flags][width][.precision][{h | l | ll | I32 | I64}]type

3 before, 2 after, plus the dot,  is a total width of six (6) places.

void OnStart(){
   Print( StringFormat("'%06.2f,%06.2f,%06.2f'", 1.12345, 12.12345, 123.12345) );  // '001.12,012.12,123.12'
}


It does work. Your image shows "%03.1f" and 70.1 which requires a minimum of 4 digits to display (7,0,".",1) and you specified width 3, so no zero.

PrintFormat - Common Functions - MQL4 Reference
PrintFormat - Common Functions - MQL4 Reference
  • docs.mql4.com
PrintFormat - Common Functions - MQL4 Reference
Carl Schreiber
6588
Carl Schreiber 2016.11.09 21:38  

Ahh - ok, I see my mistake, the total numbers of char has to be before the decimal point - not after. :(

Thank you

To add comments, please log in or register