FormatCurrency, FormatNumber, FormatPercent Functions

   
FormatCurrency, FormatNumber, FormatPercent Functions

Class

Microsoft. VisualBasic. Strings

Syntax

 FormatCurrency(   expression   [,   NumDigitsAfterDecimal   ][, _   IncludeLeadingDigit   [,   UseParensForNegativeNumbers   [, _   GroupDigits   ]]]])  FormatNumber(   expression   [,   NumDigitsAfterDecimal   ][, _   IncludeLeadingDigit   [,   UseParensForNegativeNumbers   [, _   GroupDigits   ]]]])  FormatPercent(   expression   [,   NumDigitsAfterDecimal   ][, _   IncludeLeadingDigit   [,   UseParensForNegativeNumbers   [, _   GroupDigits   ]]]]) 
expression (required; Object)

The number or numeric expression to be formatted.

NumDigitsAfterDecimal (optional; Long)

The number of digits the formatted string should contain after the decimal point.

IncludeLeadingDigit (optional; TriState constant)

Indicates whether the formatted string is to have a 0 before floating point numbers between 1 and -1.

UseParensForNegativeNumbers (optional; TriState constant)

Specifies whether parentheses should be placed around negative numbers.

GroupDigits (optional; TriState constant)

Determines whether digits in the returned string should be grouped using the delimiter specified in the computer's regional settings. For example, on English language systems, the value 1000000 is returned as 1,000,000 if GroupDigits is True .

Return Value

String

Description

Functions used to format currency, numbers, and percentages.

The three functions are almost identical. They all take identical arguments. The only difference is that FormatCurrency returns a formatted number beginning with the currency symbol specified in the computer's regional settings, FormatNumber returns just the formatted number, and FormatPercent returns the formatted number followed by a percentage sign ( % ).

Rules at a Glance

  • If NumDigitsAfterDecimal is not specified, its default value is -1, which means that the value in the computer's regional settings is used.

  • The TriState constant values are True , False , and UseDefault .

  • When optional arguments are omitted, their values are defined by the computer's regional settings.

  • In the FormatCurrency function, the position of the currency symbol in relation to the currency value is defined by the computer's regional settings.

Programming Tips and Gotchas

These three functions first appeared in VBScript Version 2 as "light" alternatives to the Format function, which had originally been left out of VBScript due to its size . They are quick and easy to use and make your code more self-documenting ; you can instantly see what format is being applied to a number without having to decipher the format string.

See Also

Format Function, FormatDateTime Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net