cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
miguello
Level VII

How to convert a number to string using specific format? For instance: {"Scientific", 12}

As a subject suggests, I need to convert a number to string using a specific format. To be precise: I have a handle on GB plot, and Text() near that handle that outputs current coordinates of the handle:

Text( Erased, {box:exx, box:exy} + box:axisRange * 0.01, "(" || Char( Round( box:exx, 2 ) ) || "," || Char( Round( box:exy, 2 ) ) || ") " ) ;

On some plots the Y Axis is very small and is displayed in Scientific format:  {"Scientific", 12}

The idea is to grab the format from the axis (both of them) and format corresponding coordinates written in the Text() accordingly (instead of doing Round(xyz, 2).

I tried a few different approaches, but they all error out. 

Any suggestions?

 

 

4 REPLIES 4
hogi
Level XIII

Re: How to convert a number to string using specific format? For instance: {"Scientific", 12}

Hi @miguello , you can use

Format(value, "Scientific", width, decimals)

hogi_1-1758948507750.png

 

 

miguello
Level VII

Re: How to convert a number to string using specific format? For instance: {"Scientific", 12}

Ok, I tried it like below and it worked:

  aa = rgbs << XPath("//AxisBox");
  format1 = aa[1][2] << Get Format;
  format2 = aa[2][2] << Get Format;
  
  bb = 3.1415926535;
    
  Format(bb, format1[1], format1[2], format1[3]);
  Format(bb, format2[1], format2[2], format2[3]);

I have two GBs, Pulling formats from them yields:

{"Scientific", 12}

{"Fixed Dec", 12, 2}

When using as I showed it correctly formats the number, even though format1 has only two members in the list. I guess it has an internal Try() or something.

Format(bb, format1[1], format1[2], format1[3]);
/*:

"3.1415927e+0"
//:*/
Format(bb, format2[1], format2[2], format2[3]);
/*:

"3.14"

Any way to just use pulled format without spelling it by member?

 

 

hogi
Level XIII

Re: How to convert a number to string using specific format? For instance: {"Scientific", 12}

Many unnamed arguments in Jmp are optional.

 

You need to insert the value .

As an alternative you can use

Insert (Substitute(format1,{},Expr(Format())),expr(value),1)

hogi_1-1759001765925.png

 

It looks much more complicated. The benefit: 

Independent of the number of settings.

 

Another approach: inverting the 2 steps

Substitute(insert({value},format1),{},Expr(Format()))

hogi_2-1759001791786.png


One of the few cases where it helps that Insert flattens the result:
 JMP Expr() weirdness, can anyone explain? 
For all the other cases, I hope Insert will get a new option ; )
Insert Into: Flatten(0|1) 

jthi
Super User

Re: How to convert a number to string using specific format? For instance: {"Scientific", 12}

Have you just tried using the list of the parameters?

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

gb = dt << Graph Builder(
	Size(525, 454),
	Show Control Panel(0),
	Variables(X(:weight), Y(:height), Overlay(:sex)),
	Elements(Points(X, Y, Legend(9)), Line Of Fit(X, Y, Legend(11))),
	SendToReport(
		Dispatch({}, "weight", ScaleBox, {Format("Scientific", 12)}),
		Dispatch({}, "height", ScaleBox, {Format("Fixed Dec", 12, 2)})
	)
);

abs = gb << XPath("//AxisBox");
xaxis_format = abs[1] << get format;
yaxis_format = abs[2] << get format;

bb = 3.1415926535;
Show(Format(bb, xaxis_format)); // Format(bb, xaxis_format) = "3.1415927e+0";
Show(Format(bb, yaxis_format)); // Format(bb, yaxis_format) = "3.14";
-Jarmo

Recommended Articles