FormatNumber

Navigation:  Appendices > Macro Language > Built-in Functions > All Functions (Alphabetical) >

FormatNumber

Previous pageReturn to chapter overviewNext page

str = FormatNumber(sFormat,nNumber)

 

This macro function formats a number according to rules you set for thousands separators, negative numbers, zero values and blank digits.

 

sOut = FormatNumber('#,##0', nPageNumber)

 

The format string is made up of :

 

0

Digit place holder. If the value being formatted has a digit in the position where the '0' appears in the format string, then that digit is copied to the output string. Otherwise, a '0' is stored in that position in the output string.

#

Digit placeholder. If the value being formatted has a digit in the position where the '#' appears in the format string, then that digit is copied to the output string. Otherwise, nothing is stored in that position in the output string.

,

Thousand separator. If the format string contains one or more ',' characters, the output will have thousand separators inserted between each group of three digits to the left of the decimal point. The placement and number of ',' characters in the format string does not affect the output, except to indicate that thousand separators are wanted. The actual character used as a the thousand separator in the output is determined by the ThousandSeparator global variable. The default value of ThousandSeparator is specified in the Number Format of the International section in the Windows Control Panel.

 

Note that :

 

Characters enclosed in double quotes are output as-is, and do not affect formatting.

';' Separates sections for positive, negative, and zero numbers in the format string.

The location of the '0' in the format string determines the number of digits that are always present in the output string.

 

To allow different formats for positive, negative, and zero values, the format string can contain between one and three sections separated by semicolons.

 

One section: The format string applies to all values.

Two sections: The first section applies to positive values and zeros, and the second section applies to negative values.

Three sections: The first section applies to positive values, the second applies to negative values, and the third applies to zeros.

 

If the section for negative values or the section for zero values is empty, that is if there is nothing between the semicolons that delimit the section, the section for positive values is used instead.

 

Consider the numbers 1234, -1234 and 0 using the following formats :

 


'' (blank)

1234

-1234

0.


'0'

1234

-1234

0.


'#'

1234

-1234

(nothing)


'#,##0'

1,234

-1,234

0


'#,##0;(#,##0)'

1,234

(1,234)

0


'#,##0;;Zero'

1,234

-1,234

Zero

 

Note that, as was the case for FormatDate, this function depends on the settings of Windows on your workstation to decide what the thousands separator is, which would limit the use of this function to text for internal use, usually outside of the trim area.


Topic 108260 updated on 24-Mar-2003.
Topic URL: http://www.qppstudio.net/webhelp/index.html?formatnumber.htm