Article ID 1387
Article Title HOWTO: Obtaining currency information from the Windows locale
Article URL http://www.dataaccess.com/kbasepublic/kbprint.asp?ArticleID=1387
KBase Category Visual DataFlex
Date Created 05/27/2001
Last Edit Date 03/11/2004


Article Text
QUESTION:
How to get various currency information from your Windows local settings?

ANSWER:
Use code from the following sample:
Use Windows.Pkg
Use Dferror.Pkg

Define LOCALE_SCURRENCY       For |CI$00000014 // local monetary symbol
Define LOCALE_SINTLSYMBOL     For |CI$00000015 // intl monetary symbol
Define LOCALE_SMONDECIMALSEP  For |CI$00000016 // monetary decimal separator
Define LOCALE_SMONTHOUSANDSEP For |CI$00000017 // monetary thousand separator
Define LOCALE_SMONGROUPING    For |CI$00000018 // monetary grouping
Define LOCALE_ICURRDIGITS     For |CI$00000019 // # local monetary digits
Define LOCALE_IINTLCURRDIGITS For |CI$0000001A // # intl monetary digits
Define LOCALE_ICURRENCY       For |CI$0000001B // positive currency mode
Define LOCALE_INEGCURR        For |CI$0000001C // negative currency mode

// Position of the monetary symbol in the positive currency mode.
// The maximum number of characters allowed for this string is two. The mode can
// be one of the following values.
// Return values:
// 0 Prefix, no separation, for example $1.1
// 1 Suffix, no separation, for example 1.1$
// 2 Prefix, 1-character separation, for example $ 1.1
// 3 Suffix, 1-character separation, for example 1.1 $
Function PositiveCurrencyMode Returns Integer
   String sPositiveCurrencyMode
   Integer iVoid

   ZeroString 2 To sPositiveCurrencyMode
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ICURRENCY, AddressOf (sPositiveCurrencyMode), 2)) To iVoid

   Function_Return (Cstring (sPositiveCurrencyMode))
End_Function // PositiveCurrencyMode

// Negative currency mode. The maximum number of characters allowed for this
// string is three. The mode can be one of the following values. Mode Format
// for a negative currency
// 0 Left parenthesis,monetary symbol,number,right parenthesis. Example: ($1.1)
// 1 Negative sign, monetary symbol, number. Example: -$1.1
// 2 Monetary symbol, negative sign, number. Example: $-1.1
// 3 Monetary symbol, number, negative sign. Example: $1.1-
// 4 Left parenthesis, number, monetary symbol, right parenthesis. Example: (1.1$)
// 5 Negative sign, number, monetary symbol. Example: -1.1$
// 6 Number, negative sign, monetary symbol. Example: 1.1-$
// 7 Number, monetary symbol, negative sign. Example: 1.1$-
// 8 Negative sign, number, space, monetary symbol (like #5, but with a space before the monetary symbol). Example: -1.1 $
// 9 Negative sign, monetary symbol, space, number (like #1, but with a space after the monetary symbol). Example: -$ 1.1
// 10 Number, space, monetary symbol, negative sign (like #7, but with a space before the monetary symbol). Example: 1.1 $-
// 11 Monetary symbol, space, number, negative sign (like #3, but with a space after the monetary symbol). Example: $ 1.1-
// 12 Monetary symbol, space, negative sign, number (like #2, but with a space after the monetary symbol). Example: $ -1.1
// 13 Number, negative sign, space, monetary symbol (like #6, but with a space before the monetary symbol). Example: 1.1- $
// 14 Left parenthesis, monetary symbol, space, number, right parenthesis (like #0, but with a space after the monetary symbol). Example: ($ 1.1)
// 15 Left parenthesis, number, space, monetary symbol, right parenthesis (like #4, but with a space before the monetary symbol). Example: (1.1 $)
Function NegativeCurrencyMode Returns Integer
   String sNegativeCurrencyMode
   Integer iVoid

   ZeroString 2 To sNegativeCurrencyMode
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_INEGCURR, AddressOf (sNegativeCurrencyMode), 2)) To iVoid

   Function_Return (Cstring (sNegativeCurrencyMode))
End_Function // NegativeCurrencyMode

// Number of fractional digits for the local monetary format. The maximum number
// of characters allowed for this string is three.
Function LocalCurrencyDigits Returns Integer
   String sLocalCurrencyDigits
   Integer iVoid

   ZeroString 3 To sLocalCurrencyDigits
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ICURRDIGITS, AddressOf (sLocalCurrencyDigits), 3)) To iVoid

   Function_Return (Cstring (sLocalCurrencyDigits))
End_Function // LocalCurrencyDigits

// Number of fractional digits for the international monetary format. The maximum
// number of characters allowed for this string is three.
Function IntlCurrencyDigits Returns Integer
   String sIntlCurrencyDigits
   Integer iVoid

   ZeroString 3 To sIntlCurrencyDigits
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_IINTLCURRDIGITS, AddressOf (sIntlCurrencyDigits), 3)) To iVoid

   Function_Return (Cstring (sIntlCurrencyDigits))
End_Function // IntlCurrencyDigits

// String used as the local monetary symbol. The maximum number of characters
// allowed for this string is six.
Function LocalCurrencySymbol Returns String
   String sLocalCurrencySymbol
   Integer iVoid

   ZeroString 6 To sLocalCurrencySymbol
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, AddressOf (sLocalCurrencySymbol), 6)) To iVoid

   Function_Return (Cstring (sLocalCurrencySymbol))
End_Function // LocalCurrencySymbol

// Three characters of the international monetary symbol specified in ISO 4217
// followed by the character separating this string from the amount.
Function IntlCurrencySymbol Returns String
   String sIntlCurrencySymbol
   Integer iVoid

   ZeroString 4 To sIntlCurrencySymbol
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, AddressOf (sIntlCurrencySymbol), 4)) To iVoid

   Function_Return (Cstring (sIntlCurrencySymbol))
End_Function // IntlCurrencySymbol

// Character(s) used as the monetary decimal separator. The maximum number of
// characters allowed for this string is four.
Function MonetaryDecimalSeparator Returns String
   String sMonetaryDecimalSeparator
   Integer iVoid

   ZeroString 4 To sMonetaryDecimalSeparator
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SMONDECIMALSEP, AddressOf (sMonetaryDecimalSeparator), 4)) To iVoid

   Function_Return (Cstring (sMonetaryDecimalSeparator))
End_Function // MonetaryDecimalSeparator

// Character(s) used as the monetary separator between groups of digits to the
// left of the decimal. The maximum number of characters allowed for this string is four.
Function MonetaryThousandsSeparator Returns String
   String sMonetaryThousandsSeparator
   Integer iVoid

   ZeroString 4 To sMonetaryThousandsSeparator
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SMONTHOUSANDSEP, AddressOf (sMonetaryThousandsSeparator), 4)) To iVoid

   Function_Return (Cstring (sMonetaryThousandsSeparator))
End_Function // MonetaryThousandsSeparator

// Sizes for each group of monetary digits to the left of the decimal. An explicit size is
// needed for each group, and sizes are separated by semicolons. If the last value is zero,
// the preceding value is repeated. For example, to group thousands, specify 3;0. Indic
// languages group the first thousand and then group by hundreds.
// for example, 12,34,56,789, which is represented by 3;2;0. The maximum number of
// characters allowed for this string is four
Function MonetaryGrouping Returns String
   String sMonetaryGrouping
   Integer iVoid

   ZeroString 4 To sMonetaryGrouping
   Move (GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SMONGROUPING, AddressOf (sMonetaryGrouping), 4)) To iVoid

   Function_Return (Cstring (sMonetaryGrouping))
End_Function // MonetaryGrouping

Showln "LocalCurrencySymbol: " (LocalCurrencySymbol (Self))
Showln "IntlCurrencySymbol: " (IntlCurrencySymbol (Self))
Showln "MonetaryDecimalSeparator: " (MonetaryDecimalSeparator (Self))
Showln "MonetaryThousandsSeparator: " (MonetaryThousandsSeparator (Self))
Showln "MonetaryGrouping: " (MonetaryGrouping (Self))
Showln "LocalCurrencyDigits: " (LocalCurrencyDigits (Self))
Showln "IntlCurrencyDigits: " (IntlCurrencyDigits (Self))
Showln "PositiveCurrencyMode: " (PositiveCurrencyMode (Self))
Showln "NegativeCurrencyMode: " (NegativeCurrencyMode (Self))

Send Info_Box "Ready"


Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu


Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2024 Data Access Corporation. All rights reserved.

The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.