cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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?

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
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

 

 

View solution in original post

jthi
Super User

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

Ok, it might be version dependent then (I tried with JMP18/19). The sure way of doing this is using something like hogi did already demonstrate with the substitute+insert.

Names Default To Here(1);

f = {"Scientific", 12};
bb = 3.1415926535;

myval_format = Insert(f, bb, 1);

myval_str = Eval(Substitute(myval_format, {}, Expr(Format())));
-Jarmo

View solution in original post

6 REPLIES 6
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
miguello
Level VII

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

For some reason that doesn't work in my case:

 

  bb = 3.1415926535;
  Show(format2);  //format2 = {"Fixed Dec", 12, 2};
  Show(Format(bb, format2)); //Format(bb, format2) = "01/01/1904";

I'm on JMP 17.2

jthi
Super User

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

Ok, it might be version dependent then (I tried with JMP18/19). The sure way of doing this is using something like hogi did already demonstrate with the substitute+insert.

Names Default To Here(1);

f = {"Scientific", 12};
bb = 3.1415926535;

myval_format = Insert(f, bb, 1);

myval_str = Eval(Substitute(myval_format, {}, Expr(Format())));
-Jarmo

Recommended Articles