FORMAT$

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > String functions >

FORMAT$

 

Description

 

Format numeric data according to instructions contained in a format expression.

 

Syntax

 

s = FORMAT$(NumericExpression [, [NumberOfDigits | FormatString]])

 

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

NumericExpression

Numeric

No

Number to be formatted

NumberOfDigits

Numeric

Yes

The maximum number of significant digits in range of 1 to 18. If not specified a default 16 will be used

FormatString

String

Yes

Format characters that will determine how the numeric expression should be formatted. There may be up to 18 digit-formatting digits on either side of the decimal point.  The mask may not contain literal characters unless each character is preceded with a backslash (\) escape character, or the literal characters are enclosed in quotes.

 

FormatString may contain one, two or three formatting masks, separated by semicolon (;) characters:

 

One mask

If FormatString contains just one format mask, the mask is used to format all possible values of num_expression.

For example: s = FORMAT$(z, "000.00")

 

Two masks

If FormatString contains two format masks, the first mask is used for positive values (=> 0), and the second mask is used for negative values (< 0).

For example: s = FORMAT$(-100, "+00000.00;-000")

 

Three masks

If FormatString contains three masks, the first mask is used for positive values (> 0), the second mask for negative values (< 0), and the third mask is used if num_expression is zero (0).

For example:

For y = -0.5 To 0.5 Step 0.5

  s = FORMAT$(y, "+.0;-.0; .0")

Next

 

Digit placeholders in a mask do not have to be contiguous. This allows you to format a single number into multiple displayed parts.

For example: s = FORMAT$(123456, "00\:00\:00")   '---12:34:56

 

 

Remarks

 

Restrictions

 

See also

 

String Handling,

 

Examples