Publication date: 07/08/2024

Format Numbers

The Format() function provides options for formatting numbers with thousands separators, decimal points, geographic symbols, p-values, and so on. The following example shows a basic format for a fixed decimal column.

Format( x, "Fixed Dec", 10, 2, "Use thousands separator");

The format starts with the number to be formatted. Then you can specify the width of the number, the number of decimal places, and whether to use a thousands separator.

Here are other examples:

Format( x, "Currency", 20, <<Use Locale(0) );
	// ignores computer locale and uses a period for the decimal separator
Format( x, "Currency", 20, "Use thousands separator" );
Format( x, "m/d/y", 10 );
Format( x, "Precision", 10, 2, "Keep trailing zeroes", "Keep all whole digits" );
Format( x, "Latitude DDD", "PUNDIR"); // "PUN" for punctuation, "DIR" for direction, PUNDIR for both
Format( x, "Custom", Formula( Abs( value ) ), 15 );

The syntax for Function() arguments is shown in Format(x, formatString, width|<width, decimal places>, <"Use Thousands Separator">) in the JSL Syntax Reference. You can also find the argument names and options in the data table Column Info window.

See Date-Time Functions and Formats and Format Currency for more information about formatting date-time values and currency.

Note: If the date format is unknown, an error is written to the log.

Matrix Box, Number Col Box, Number Col Edit Box, Number Edit Box

To format numbers in Matrix Box(), Number Col Box(), Number Col Edit Box(), and Number Edit Box(), send the Set Format message to the display box. You can then specify the same arguments as for the Format() function, such as the following:

<<Set Format( 10, 2, "Use thousands separator");
<<Set Format( "Currency", "EUR", 20 );

The syntax for Set Format arguments is shown in Number Col Box<<Set Format(<width>|<width, decimal places>, <"Use Thousands Separator">) in the JSL Syntax Reference. You can also find the argument names and options in the data table Column Info window.

Note: If you specify the number of decimal places, that number must be preceded with the width.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).