Page 1 of 1

numtostr function and decimals

Posted: 10 Mar 2011
by fibdax
Using the function numtostring to plot the value of the maximum or minimum on the graph.
if you use numtostr (High, 2) the value appears correctly with decimals.
if I use input: decimal (x) and numtostr (High, decimal) the value is truncated without decimals.
someone knows why '?
thanks

Re: numtostr function and decimals

Posted: 10 Mar 2011
by TJ
Using the function numtostring to plot the value of the maximum or minimum on the graph.
if you use numtostr (High, 2) the value appears correctly with decimals.
if I use input: decimal (x) and numtostr (High, decimal) the value is truncated without decimals.
someone knows why '?
thanks
what value did you put in as "x" in decimal (x)?

Re: numtostr function and decimals

Posted: 13 Mar 2011
by piranhaxp
Fibdax,

like TJ said :

input : decimal(2);

var : High_txt("");

high_txt=numtostr(h,decimal);

Regards.

Mike

Re: numtostr function and decimals

Posted: 13 Mar 2011
by CrazyNasdaq
Try this way, it will work:

input : decimal(2);

var : High_txt("");

high_txt=text(numtostr(h,decimal));

Re: numtostr function and decimals

Posted: 13 Mar 2011
by piranhaxp
CrazyNasdaq,

where's the difference with

high_txt=text(numtostr(h,decimal));

and my proposal if you call the "text_var" later in a plot or text statement ? I don't see it.
An explanation would be nice, because I never used the text(......)-statement.

Thanks a lot.

Regards.

Mike

Re: numtostr function and decimals

Posted: 13 Mar 2011
by CrazyNasdaq
the function "numtostr" transforms a numeric value into a string.

If you assign to a variable a Text statement as High_Txt(""), it must be already a text.
With this trick, using Text(numtostr(valueA, decimals)) you force the code the get the right implementation.

Try that way and it will not be truncated.

Re: numtostr function and decimals

Posted: 13 Mar 2011
by piranhaxp
So you are saying if I have to implement variable text into the code, then it is necessary to implement numtostr-functions into your text(....) proposal ?

With all respect your note :
If you assign to a variable a Text statement as High_Txt(""), it must be already a text.
With this trick, using Text(numtostr(valueA, decimals)) you force the code the get the right implementation.
in my experience is wrong.

It is not necessary that high_txt("") is already a text, because var : high_txt("") already defined it as text. Therefore we have this numtostr-function, which able us to transform numerical values into string.

I'm always working like this :

var: txtr1("")
var: min1rid(-1);

txtr1=" minHExp. "+numtostr(....,autodecimals)+" > "+numtostr(....,autodecimals);

if min1rid<0 then begin
min1rid=text_new(date,time,....,txtr1);
text_setstyle(min1rid,0,2);
text_setcolor(min1rid,text_color);
text_setsize(min1rid,text_size);
end
else
begin
text_setstring(min1rid,txtr1);
text_setlocation(min1rid,date,calctime(time+(2*barinterval),1),....);
text_setcolor(min1rid,text_color);
text_setsize(min1rid,text_size);
end;
May your style to define it is working well, but with my way I get the same result. I will test your way tomorrow in real-time and will check for any improvements system wise.

Thanks a lot.

Regards.

Mike

Re: numtostr function and decimals

Posted: 14 Mar 2011
by CrazyNasdaq
You are right, but you wrote that you get a truncated string.
I use "numtostr" as you write too, but using "text" you can solve that bug/problem.
It was simply a solution, but you can write your code the way you prefer.

Regards

Re: numtostr function and decimals

Posted: 14 Mar 2011
by piranhaxp
CrazyNasdaq,
You are right, but you wrote that you get a truncated string
I never said this .... But thx for your reply.

Regards.

Mike

Re: numtostr function and decimals

Posted: 16 Mar 2011
by fibdax
thank you all now I try the code