FORMAT

The FORMAT script function lets you format numbers by adding or removing leading zeros. You can specify the number of leading zeros to add or remove, and you can specify the number of decimal places in floating-point numbers.

Syntax

FORMAT (number [,format])

Parameters

Return code: Number with or without leading zeros, depending on what you specify


Notes:

Examples

The following example removes leading zeros from the 16-digit return code of the SYS_BUSY_60 script function, and prints the result in the activation report:

:SET &SRV#=SYS_BUSY_60()
:
SET &RET#=FORMAT(&SRV#)
:
PRINT &RET#

The following example adds leading zeros to reach the specified length of 5 digits, and prints the result (00125) in the activation report:

:SET &RET#=FORMAT("125","00000")
:
PRINT &RET#

The following example removes leading zeros, and prints the result (333) in the activation report:

:SET &RET#=FORMAT("0000333","00")
:
PRINT &RET#

In the following example, the number does not change because there are no leading zeros, so the number fits the specified format as is:

:SET &RET#=FORMAT("555","00")
:
PRINT &RET#

The following example formats a floating-point number so that it has only one decimal place, and prints the result (-0.7) in the activation report: 

:DEFINE &NUM#,float
:DEFINE &RET#,string
:SET &NUM#=-0.75
:
SET &RET#=FORMAT(&NUM#,"00.0")
:
PRINT &RET#

The following example removes all decimal places, and prints the result (0000) to the activation report:

:DEFINE &NUM#,float
:DEFINE &RET#,string
:SET &NUM#=0.65
:
SET &RET#=FORMAT(&NUM#,"0000")
:
PRINT &RET#

See also:

seealso

Arithmetic Calculations in Scripts