Formatting Numbers, Currency, and Percents in VB: Thevbprogramer
Formatting Numbers, Currency, and Percents in VB: Thevbprogramer
Written By TheVBProgramer.
$ReqTestHarness$
FormatNumber(Expression[,NumDigitsAfterDecimal [,IncludeLeadingDigit
[,UseParensForNegativeNumbers [,GroupDigits]]]])
Where:
The syntax for FormatCurrency and FormatPercent are exactly the same as
FormatNumber.
For the examples below, assume dblTestNumber contains the value 12345.678
Expression Result
End Sub
Output:
Download the VB project code for the example above here.
Syntax:
FormatDateTime(Date[,NamedFormat])
Part Description
NamedFormat Optional. Numeric value that indicates the date/time format used. If
omitted, vbGeneralDate is used.
Settings:
vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a shor
date. If there is a time part, display it as a long time. If present, both
parts are displayed.
vbLongDate 1 Display a date using the long date format specified in your computer
regional settings.
vbShortDate 2 Display a date using the short date format specified in your compute
regional settings.
vbLongTime 3 Display a time using the time format specified in your computer's
regional settings.
End Sub
Output:
FormatDateTime(Now, vbLongDate)
instead of:
FormatDateTime(Now, 1)