The GetCurrencyFormat API function formats a string. This example lets you set the locale ID to LOCALE_SYSTEM_DEFAULT, LOCALE_USER_DEFAULT, or 0. If you set it to 0, the program lets you specify the number of digits after the decimal separator, whether to pad those digits with zeros if necessary, the number of digits per grouping, the thousands and decimal separators, the method for handling negative numbers (e.g. -$1 versus ($1) versus $1-), and the method for handling positive numbers (e.g. $1 versus $ 1 versus 1$).
GetCurrencyFormat places the formatted result in a buffer and returns the length of the buffer.
|
' Format a numeric string.
Private Function FormatCurrency(ByVal numeric_string As _
String, ByVal locale_id As Long, ByVal num_digits As _
Integer, ByVal leading_zero As Boolean, ByVal _
num_per_group As Integer, ByVal decimal_separator As _
String, ByVal thousands_separator As String, ByVal _
negative_order As Long, ByVal positive_order As Long, _
ByVal currency_symbol As String) As String
Dim fmt As CURRENCYFMT
Dim buf As String * 200
Dim buflen As Integer
With fmt
.NumDigits = num_digits
If leading_zero Then
.LeadingZero = 1
Else
.LeadingZero = 0
End If
.Grouping = num_per_group
.lpDecimalSep = decimal_separator
.lpThousandSep = thousands_separator
.NegativeOrder = negative_order
.PositiveOrder = positive_order
.lpCurrencySymbol = currency_symbol
End With
If locale_id = 0 Then
buflen = GetCurrencyFormat(locale_id, 0, _
numeric_string, fmt, buf, Len(buf))
Else
buflen = GetCurrencyFormat(locale_id, 0, _
numeric_string, ByVal 0&, buf, Len(buf))
End If
FormatCurrency = Left$(buf, buflen)
End Function
|