Str Function

Action

Converts a number to the corresponding character string.

Syntax

sNum = Str (nNum [, iWidth, iDec])
Variable Description
sNum The returned character. STRING.
nNum The number to convert to a character string. NUMBER.
iWidth Optional. The length in characters of the string returned, including digits, decimal point, and sign. INTEGER.
iDec Optional. The number of decimal places to include in the string returned. INTEGER.

Notes

Str returns a string that corresponds to nNum, including a decimal point and decimal places if iDec is specified and is greater than zero. If iDec is omitted, no decimal places are included.

If iWidth is insufficient to hold the new string, Str increases it to the appropriate length.

If iDec is less than the number of decimal places in nNum, Str rounds the number at the least significant digit before converting it to a string.

An exception is raised if iWidth or iDec is less than zero.

Example

NUMBER n = 123.789
Print (Str (n)) // prints 124
Print (">{Str (n,5)}<") // prints > 124<
Print (">{Str (n,4,2)}<") // prints >123.79<