Format

From NSB App Studio
Revision as of 13:18, 6 July 2012 by Ghenne (talk | contribs)
Jump to navigation Jump to search
FORMATCURRENCY(expression[, fractionaldigits[, leadingdigit[, parensfornegative[, groupdigits]]]])

FORMATDATETIME(date[, formatname])

FORMATNUMBER(expression[, fractionaldigits[, leadingdigit[, parensfornegative[, groupdigits]]]])

FORMATPERCENT(expression[, fractionaldigits[,leadingdigit[, parensfornegative[, groupdigits]]]])

Description

FORMATCURRENCY, FORMATNUMBER, and FORMATPERCENT return a string obtained by formatting the given expression as a currency, number, or percent. The required parameter, expression, is any valid expression of the given type. The optional parameter, fractionaldigits, is a numeric expression representing the number of digits to print after the decimal, the default is -1 which uses the system settings. The optional parameters, leadingdigit, parensfornegative, and groupdigits, are numeric expressions or constants, see below. leadingdigit specifies whether a leading zero is printed for numbers with only fractional parts. parensfornegative specifies if negative values are to be printed with enclosing parentheses. groupdigits specifies if numbers are to be printed in groups using the systems group delimiter.

Table 11: Tristate values

Name Value Description
True -1 True
False 0 False
TriStateUseDefault -2 Use system settings

FORMATDATETIME returns a string obtained by formatting a date. The required parameter, date, is any valid expression that represents a date. The optional parameter, formatname, is a numeric expression or constant that specifies how the date is formatted.

Table 12: formatname constants

Constant Value Description
vbGeneralDate 0 Short date, Long time
vbLongDate 1 Long date
vbShortDate 2 Short date
vbLongTime 3 Long time
vbShortTime 4 Short time

Example

REM Format Functions 
DIM UseDefault
UseDefault=-2
'Currency
PRINT FORMATCURRENCY(-3.5, -1, _
       TristateUseDefault, True)
PRINT FORMATCURRENCY(123456, 0,True, False, True)
'Date/Time
PRINT FORMATDATETIME(NOW)
PRINT FORMATDATETIME(Birthdate, vbLongDate)
'General Numbers
PRINT FORMATNUMBER(-0.1429, 6,False)
PRINT FORMATNUMBER(987654.321, 3, True, False, True)
'Percentages
PRINT FORMATPERCENT(0.007, 2, False)
PRINT FORMATPERCENT(1234.56, 0,True, False, False)

Output

($3.50)
$123,456
8/18/1998 10:44 PM
August 18, 1998
-.142900
987,654.321
.70%
123456%
(sample output is system dependant)