numtostr function and decimals

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
fibdax
Posts: 88
Joined: 03 Jan 2011
Has thanked: 5 times
Been thanked: 4 times

numtostr function and decimals

Postby fibdax » 10 Mar 2011

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

User avatar
TJ
Posts: 6598
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1909 times

Re: numtostr function and decimals

Postby TJ » 10 Mar 2011

fibdax wrote: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)?

User avatar
piranhaxp
Posts: 236
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 29 times

Re: numtostr function and decimals

Postby piranhaxp » 13 Mar 2011

Fibdax,

like TJ said :

input : decimal(2);

var : High_txt("");

high_txt=numtostr(h,decimal);

Regards.

Mike

User avatar
CrazyNasdaq
Posts: 265
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 78 times
Been thanked: 80 times

Re: numtostr function and decimals

Postby CrazyNasdaq » 13 Mar 2011

Try this way, it will work:

input : decimal(2);

var : High_txt("");

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

User avatar
piranhaxp
Posts: 236
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 29 times

Re: numtostr function and decimals

Postby piranhaxp » 13 Mar 2011

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

User avatar
CrazyNasdaq
Posts: 265
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 78 times
Been thanked: 80 times

Re: numtostr function and decimals

Postby CrazyNasdaq » 13 Mar 2011

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.

User avatar
piranhaxp
Posts: 236
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 29 times

Re: numtostr function and decimals

Postby piranhaxp » 13 Mar 2011

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

User avatar
CrazyNasdaq
Posts: 265
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 78 times
Been thanked: 80 times

Re: numtostr function and decimals

Postby CrazyNasdaq » 14 Mar 2011

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

User avatar
piranhaxp
Posts: 236
Joined: 18 Oct 2005
Has thanked: 4 times
Been thanked: 29 times

Re: numtostr function and decimals

Postby piranhaxp » 14 Mar 2011

CrazyNasdaq,

You are right, but you wrote that you get a truncated string


I never said this .... But thx for your reply.

Regards.

Mike

fibdax
Posts: 88
Joined: 03 Jan 2011
Has thanked: 5 times
Been thanked: 4 times

Re: numtostr function and decimals

Postby fibdax » 16 Mar 2011

thank you all now I try the code


Return to “User Contributed Studies and Indicator Library”