Format

Top  Previous  Next

×V2.1Ø

S

A

W

WS

ü

ü

Syntax -

Format <variable name> <source value> <pattern>

       Where:

       <variable name> is the user defined name that is assigned to the variable.

       <source value> is a numeric value or a variable that contains a numeric value.

       <pattern> is a literal string or a variable that contains a string.

       

Description:

This command is used to format numeric values.  The <source value> will be converted to the format specified in <pattern> and the result will be stored in <variable name>.  See tables below for predefine formats and customizable formats.

 

       Predefined Formats

Format Name

Description

General Number, G, or g

Formats number with no comma for thousands.  This format is useful for stripping commas out of a number and for removing leading zeroes.

Currency, C, or c

Formats number with a comma separating the thousands; displays two digits to the right of the decimal point.

Fixed, F, or f

Formats at least one digit to the left and two digits to the right of the decimal point.

Standard, N, or n

Formats number with comma separating thousands, at least one digit to the left and two digits to the right of the decimal point.

Percent

Multiplies number by 100 appends a percent sign (%) immediately to the right; always displays two digits to the right of the decimal point.

P, or p

Multiplies number by 100 with a percent sign (%) appended to the right and separated by a single space; always displays two digits to the right of the decimal separator; includes comma separating thousands.

 

Note: The FORMAT command has the same format options as the format command in VB.NET.  For more details about predefined formats and to see other formats, see the VB.NET language reference at https://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

Note: To preserve leading zeros in a source value, include a 0 at the beginning of the desired pattern. For more details, see the description for character (0) below.

 

       Custom Formatting Characters

Character

Description

(0)

The digit placeholder displays a digit or a zero. If the expression has a digit in the position where the zero appears in the format string, the digit is displayed; otherwise, a zero is displayed in that position.

"0.00" will format a number so that there are always two places after the decimal point.  After the following command, output will equal "185.50"

FORMAT output "185.5" "0.00"

(#)

Digit placeholder.  If the expression has a digit in the position where the # character appears in the format string, the digit is displayed; otherwise,  nothing is displayed in that position.

The following formats output to look like a social security number.

FORMAT output "123456789" "###-##-####"

(.)

Decimal placeholder.

FORMAT output "185.5" "0.00"

(%)

Percent placeholder. Multiplies the expression by 100 and inserts the percent character (%) into the position where it appears in the format string.

(,)

Including a comma (,) in the formatting string will cause a comma to separate thousands from hundreds within a number that is greater than or equal to 1,000.

After the following line, output will equal "1,805.50"

FORMAT output "1805.5" "0,0.00"

(\)

Displays the next character in the format string. To display a character that has special meaning as a literal character, precede it with a backslash (\). The backslash itself isn't displayed.  To display a backslash,  two backslashes (\\) must be used.

Some characters cannot be displayed as literal characters when using the FORMAT command.  These characters include a, c, d, h, m, n, p, q, s, t, w, y, /, :, #, 0, %, E, e, @, &, <, >, !, comma, and period.

The following line appends a (#) to the beginning of the variable myVar.

FORMAT output myVar "\##"

 

Note: The FORMAT command has the same format options as the format command in vb.net.  For more details about custom formats and to see more custom formatting characters , see the vb.net language reference at https://msdn.microsoft.com/en-us/library/0c899ak8.aspx.