Declare Function GetCurrencyFormat Lib "kernel32.dll" Alias "GetCurrencyFormatA" (ByVal Locale As Long, ByVal dwFlags As Long, ByVal lpValue As String, lpFormat As Any, ByVal lpCurrencyStr As String, ByVal cchCurrency As Long) As Long
GetCurrencyFormat formats a currency value for display. By default, the function formats the currency according to the specified locale's settings. However, custom formatting preferences can instead be used. The end result of GetCurrencyFormat is a currency amount displayed according to the user's preferences.
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns the number of characters copied into the string passed as lpNumberStr, not including the terminating null character.
When passing 0 for the lpFormat parameter, the expression ByVal CLng(0) must be used. See the example code for a demonstration of this.
Const LOCALE_SYSTEM_DEFAULT = &H400
Const LOCALE_USER_DEFAULT = &H800
Const LOCALE_NOUSEROVERRIDE = &H80000000
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Type CURRENCYFMT
NumDigits As Long
LeadingZero As Long
Grouping As Long
lpDecimalSep As String
lpThousandSep As String
NegativeOrder As Long
PositiveOrder As Long
lpCurrencySymbol As String
End Type
Public Declare Function GetCurrencyFormat Lib "kernel32.dll" Alias "GetCurrencyFormatA" _
(ByVal Locale As Long, ByVal dwFlags As Long, ByVal lpValue As String, lpFormat _
As Any, ByVal lpCurrencyStr As String, ByVal cchCurrency As Long) As Long
Const LOCALE_USER_DEFAULT = &H800
' Display the amount of $1,234,567.89 according to two formatting rules.
' 1. Use the format specified by the current user locale.
' 2. Use a custom format specified by a structure passed to the function.
Dim cft As CURRENCYFMT ' custom formatting settings
Dim formatted As String ' receives the formatted number strings
Dim strlen As Long ' the length of the formatted string
' Display the value formatted according to the current locale.
formatted = Space(256)
strlen = GetCurrencyFormat(LOCALE_USER_DEFAULT, 0, "1234567.89", ByVal CLng(0), _
formatted, Len(formatted))
formatted = Left(formatted, strlen)
Debug.Print "User locale format: "; formatted
' Now display according the format we specify below.
With cft
' Display three digits after the decimal point (like in US gasoline prices).
.NumDigits = 3
' Display zeros after the decimal point.
.LeadingZero = 1
' Group every three digits to the left of the decimal.
.Grouping = 3
' Use a comma to as the decimal point (like they do in France and Spain).
.lpDecimalSep = ","
' Likewise, use a period as the grouping separator.
.lpThousandSep = "."
' For negative values, place it in parentheses and put the $ sign after the digits.
.NegativeOrder = 4
' For positive values, place the $ sign after the digits.
.PositiveOrder = 1
' Use the $ sign to represent the currency.
.lpCurrencySymbol = "$"
End With
formatted = Space(256)
strlen = GetCurrencyFormat(LOCALE_USER_DEFAULT, 0, "-1234567.89", cft, formatted, _
Len(formatted))
formatted = Left(formatted, strlen)
Debug.Print "Custom format: "; formatted
Back to the Function list.
Back to the Reference section.
Last Modified: April 16, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getcurrencyformat.html