Controling the digits places at Comment code - very interesting subject

 

Hello freinds, I need your help.

As I use the "Comment" to show data on the screen, I want to controle the wideness of the comment.

For a better understanding I will give an example:

I want to have a comment line on the screen of the Stocastic indicator value.

Since it ranges from 0 to 100, and I don't care about the fractals but only the Integer number, so If Stoch = 75.28, I want

to see only the number 75.

I know How to do it: using Doubletostr(Stoch,0), or NormalizeDouble(Stoch,0).

My problem is the I want that this number will use always 3 places.

Normally, if Stoch=7 then it uses 1 places, if Stoch=45 then it uses 2 places, and if Stoch=100 it uses 3 place.

This "phenomena" creats a dynamic screen. It moves all the time, and I preffer to see it with stagnantic place (alway 3 place - Since the max is 100) as a nice and constant tablet.

Can somebody help.

Thanks.

Y.

 

no, since the coments do not use a monospace font.

You can create a textlable and use a monospace font and use something like...

if (value < 10){
txt="  "+DoubleToStr(value,0);
}else if(value < 100){
txt=" "+DoubleToStr(value,0);
}else{
txt=DoubleToStr(value,0);
}
 
zzuegg:

no, since the coments do not use a monospace font.

You can create a textlable and use a monospace font and use something like...


Thankes zzuegg,

Your idea is nice but it is complicated if you have 20 veriables...

Is there another idea, or maybe I will built a small function.

Thanks

 

make a function out of it...

String valueToStr(double value){
String txt;
if (value < 10){
txt="  "+DoubleToStr(value,0);
}else if(value < 100){
txt=" "+DoubleToStr(value,0);
}else{
txt=DoubleToStr(value,0);
}
return (txt);
}
 
zzuegg:

make a function out of it...


Thanks. It works.

Can I control the color of the text at Comment - without making it OBJECTS..?

Y.

 
nope
 
crossy:
My problem is the I want that this number will use always 3 places.
string  RJust(string s, int size, string fill="0"){
    while( StringLen(s) < size )    s = fill + s;       return(s);             }

Print(RJust(DoubleToStr(macd,0),3," "));
 
WHRoeder:


Thanks for your efforts, But I think that the other solution is better, and second I have finished it already - very good and simple.

Thank you, again.

 
WHRoeder's solution is more elegant and flexible.
 
zzuegg:
WHRoeder's solution is more elegant and flexible.


zzuegg,

You are a real GENTELMAN !

Reason: