In Delphi, how can you use data types of currencies in different currencies in different forms?

I need to write a Delphi application that retrieves records from different tables in a database, and different records will be in different currencies. Thus, I need to show a different number of decimal places and a different currency symbol for each type of currency data ($, pounds, euros, etc.) depending on the currency of the item I loaded.

Is there a way to change the currency almost globally, that is, for all the currency data displayed on the form?

+7
delphi finance
source share
2 answers

Even in the same currency, you may need to display the values ​​in a different format (for example, for delimiters), so I would recommend that you link LOCALE instead of the currency only with your values.
You can use a prime integer to store the locale identifier (LCID).
See the list here: http://msdn.microsoft.com/en-us/library/0h88fahh.aspx

Then, to display the values, use something like:

function CurrFormatFromLCID(const AValue: Currency; const LCID: Integer = LOCALE_SYSTEM_DEFAULT): string; var AFormatSettings: TFormatSettings; begin GetLocaleFormatSettings(LCID, AFormatSettings); Result := CurrToStrF(AValue, ffCurrency, AFormatSettings.CurrencyDecimals, AFormatSettings); end; function USCurrFormat(const AValue: Currency): string; begin Result := CurrFormatFromLCID(AValue, 1033); //1033 = US_LCID end; function FrenchCurrFormat(const AValue: Currency): string; begin Result := CurrFormatFromLCID(AValue, 1036); //1036 = French_LCID end; procedure TestIt; var val: Currency; begin val:=1234.56; ShowMessage('US: ' + USCurrFormat(val)); ShowMessage('FR: ' + FrenchCurrFormat(val)); ShowMessage('GB: ' + CurrFormatFromLCID(val, 2057)); // 2057 = GB_LCID ShowMessage('def: ' + CurrFormatFromLCID(val)); end; 
+7
source share

I would use SysUtils.CurrToStr (Value: Currency; var FormatSettings: TFormatSettings): string;

I would set up a TFormatSettings array, each position was configured to reflect every currency supported by your application. You will need to set the following TFormat settings fields for each array position: CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, DecimalSeparator and CurrencyDecimals.

+5
source share

All Articles