FormatValue

See Also: Locale Formatting Functions, String Functions, SetNumberFormat, SetCurrencyFormat, FormatCurrency

 

Purpose

The FormatValue function formats a number with a custom format-string.

This can be used to format a string containing numbers or currency when not using a data entry object (DEO), such as dbForm or cWebForm.

Return Type

String

Syntax

Use gFormatNumbers.pkg

 

(FormatValue( {nVar}, {sFormatString} ))

Where:

$

currency symbol as defined by windows

,

thousands separator as defined by windows

.

decimal separator as defined by windows

;

separates the positive and negative format, if the negative format is omitted the positive string is used with a preceding "-"

#

represents a digit, the quantity of tokens only matters to the right of the decimal

*

can be used to the right of the decimal, it means any number of decimals

All other characters are constants. They are just printed as displayed. E.g; the "(" and ")" for negative numbers.

If you wish to display a token as a literal, use a slash in front of it e.g. /$ would create $. Even in Germany, no matter what the currency symbol defined by windows.

Many tokens use locale information. Therefore the results will differ depending on your Regional Setting Properties for Currency.

What it Does

The custom format in the sFormatString parameter is applied to the number. It returns the formated value as a string.

The sFormatString operates very similarly to the DataDictionary masking strings.

Example

The format-string $,#.##;($,#.##) will insert thousand separators (commas) and currency symbols and truncate the number to 2 decimal places; negative numbers would appear within parentheses.

Many tokens use locale information. Therefore the results will differ depending on your Regional Setting Properties for Numbers.

Move 123222.22 to nNumber
Move ",#.## $;,-#.## $" to sFormatString
Move (FormatValue(nNumber,sFormatString)) to sString

Would result with 123.222,22 € and -123.222,22 € with German settings, but 123,222.22 $ and -123,222.22 $ with USA regional settings.

Notes