# 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

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

TJ
Posts: 6668
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 973 times
Been thanked: 1925 times

### Re: numtostr function and decimals

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)?

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

### Re: numtostr function and decimals

Fibdax,

like TJ said :

input : decimal(2);

var : High_txt("");

high_txt=numtostr(h,decimal);

Regards.

Mike

CrazyNasdaq
Posts: 268
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 79 times
Been thanked: 80 times

### Re: numtostr function and decimals

Try this way, it will work:

input : decimal(2);

var : High_txt("");

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

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

### Re: numtostr function and decimals

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

CrazyNasdaq
Posts: 268
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 79 times
Been thanked: 80 times

### Re: numtostr function and decimals

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.

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

### Re: numtostr function and decimals

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

CrazyNasdaq
Posts: 268
Joined: 02 Sep 2009
Location: ITALY
Has thanked: 79 times
Been thanked: 80 times

### Re: numtostr function and decimals

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

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

### Re: numtostr function and decimals

CrazyNasdaq,

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

Regards.

Mike

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

### Re: numtostr function and decimals

thank you all now I try the code