ObjectSetText value as whole number.

 

I need some advice, I using ObjectSetText to display some value on chart. Since the text in using 'string' format the value I want it to be display as only a whole number without decimal point and round down value. How should i go about doing it?

i.e value at 2.6, display as only 2

 
georgecheng:

I need some advice, I using ObjectSetText to display some value on chart. Since the text in using 'string' format the value I want it to be display as only a whole number without decimal point and round down value. How should i go about doing it?

i.e value at 2.6, display as only 2

U can use StrToInteger(), it will discard fractional part -> https://docs.mql4.com/convert/StrToInteger. Obviously, this would only work if the string actually contains a number...


 
gordon wrote >>

U can use StrToInteger(), it will discard fractional part -> https://docs.mql4.com/convert/StrToInteger. Obviously, this would only work if the string actually contains a number...



Thanks, I tried as suggest, but still fail to display. Is it because ObjectsetText only accept string and dont' recongise int?
bool ObjectSetText( string name, string text, int font_size, string font=NULL, color text_color=CLR_NONE)
 

I only manage to get it display a single digit using string as per following :
string var1=DoubleToStr(accountbal,0);

At least, it work for the time being, if anyone have better advice do let me know. Thanks

 
georgecheng:
Thanks, I tried as suggest, but still fail to display. Is it because ObjectsetText only accept string and dont' recongise int?
bool ObjectSetText( string name, string text, int font_size, string font=NULL, color text_color=CLR_NONE)

No, int would be cast to string automatically. There must be some other problem.

 
georgecheng:

I only manage to get it display a single digit using string as per following :
string var1=DoubleToStr(accountbal,0);

At least, it work for the time being, if anyone have better advice do let me know. Thanks

What do u mean a single digit? This should work fine as well...

 
gordon wrote >>

What do u mean a single digit? This should work fine as well...


Actually i meant whole number. Nevertheless, i think i stick to this at the moment, Thanks

btw, for ObjectSetText, is it able to insert 2 variable inside the function. example

String var1
String var2

ObjectSetText("OBJ_NAME1",var1, 20, "Tahoma", Black);


Can I add the var2 inside the same function too? Thanks

 
georgecheng:


Actually i meant whole number. Nevertheless, i think i stick to this at the moment, Thanks

btw, for ObjectSetText, is it able to insert 2 variable inside the function. example

String var1
String var2

ObjectSetText("OBJ_NAME1",var1, 20, "Tahoma", Black);


Can I add the var2 inside the same function too? Thanks

You can just concatenate the strings... For example:

ObjectSetText("OBJ_NAME1",var1 + " " + var2, 20, "Tahoma", Black);
 

Thanks again gordon, it work beautifully.