CSC106 Intermediate PC Applications and Programming
Visual Basic Formatting Functions


FormatNumber

The FormatNumber function is used to format a number with a specified number of decimal places:

      FormatNumber(num,d)

This returns a string which contains num rounded to d decimal places. Numbers greater than 999 are displayed with commas. If d is omitted, the number is formatted with two decimal places. num can be a numeric value, an expression, or a string containing a number.

FormatCurrency

The FormatCurrency function is used to format a number as a dollar amount with a specified number of decimal places:

      FormatCurrency(num,d)

This returns a string which contains num rounded to d decimal places, with a leading $. Numbers greater than 999 are displayed with commas. Negative numbers are displayed in parentheses, according to standard accounting conventions. If d is omitted, the number is formatted with two decimal places. num can be a numeric value, an expression, or a string containing a number.

FormatPercent

The FormatPercent is used to format a number as a percentage with a specified number of decimal places:

      FormatPercent(num,d)

This returns a string which contains num as a decimal with d decimal places, followed by a percent sign. If d is omitted, the number is formatted with two decimal places. num can be a numeric value, an expression, or a string containing a number.

Examples

Function Result
FormatNumber(73246.428,1) 73,246.4
FormatNumber(73246.428) 73,246.43
FormatNumber(-73246.428,2) (73,246.43)
FormatCurrency(9035.9034,2) $9,035.90
FormatNumber(2*3.55,3) 7.140
FormatPercent(.056397) 5.64%
FormatPercent(.056397,3) 5.640%


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2007