cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
aharro
Level II

Formatting numbers in a loop

Hello,

I'm formatting decimal numbers in a loop, and it works on the first row but the 2nd row and thereafter it throws a type error

		for each row(my_data,
		
			:my_col = Format( :my_col, "Fixed Dec", 16, 3, "Use thousands separator");
		);

Error: <Column "my_col" changed to type Character to match formula.>

First row everything formats fine but I can't seem to figure out why it fails after.

Thanks 

3 REPLIES 3
jthi
Super User

Re: Formatting numbers in a loop

Format() returns a string (or "quoted format"), so on first row you still have number which you use as input. Then JMP converts all the values to characters in the column -> no more number

Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(2),
	Compress File When Saved(1),
	New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2]))
);

For Each Row(dt,
	show(type(:"Column 1"n));
	:"Column 1"n = Format(:"Column 1"n, "Fixed Dec", 16, 3, "Use thousands separator")
);
-Jarmo
jthi
Super User

Re: Formatting numbers in a loop

Also there should be no need to do this in a loop as you can just change the column properties (unless you want to possibly lose some precision, then you might want to loop)

Data Table("Untitled"):Column 1 << Format(
	"Fixed Dec",
	Use thousands separator(1),
	13,
	3
);
-Jarmo
aharro
Level II

Re: Formatting numbers in a loop

Thanks for your clarification on that.

I was looking to display some long float numbers in an outline box. I needed to shorten the length of the number.
I found that Left(Char(:mycolumn), 5); is better suited for my case and I don't lose any precision.