In Delphi, come è possibile visualizzare i tipi di dati valutari in valute diverse in forme diverse?

StackOverflow https://stackoverflow.com/questions/86002

  •  01-07-2019
  •  | 
  •  

Domanda

Devo scrivere un'applicazione Delphi che estragga voci da varie tabelle in un database e voci diverse saranno in valute diverse.Pertanto, devo mostrare un numero diverso di cifre decimali e un carattere di valuta diverso per ogni tipo di dati di valuta ($, sterline, euro, ecc.) a seconda della valuta dell'articolo che ho caricato.

Esiste un modo per cambiare la valuta quasi a livello globale, ovvero per tutti i dati sulla valuta mostrati in un modulo?

È stato utile?

Soluzione

Anche con la stessa valuta, potresti dover visualizzare i valori con un formato diverso (separatori ad esempio), quindi ti consiglio di associare un LOCALE anziché la valuta solo ai tuoi valori.
È possibile utilizzare un numero intero semplice per contenere l'LCID (ID locale).
Vedi l'elenco qui: http://msdn.microsoft.com/en-us/library/0h88fahh.aspx

Quindi per visualizzare i valori, usa qualcosa come:

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;

Altri suggerimenti

Utilizzerei SysUtils.CurrToStr(Valore:Valuta;var FormatSettings:ImpostazioniFormat):corda;

Imposterei una serie di TFormatSettings, ciascuna posizione configurata per riflettere ciascuna valuta supportata dalla tua applicazione.Dovrai impostare i seguenti campi delle Impostazioni TFormat per ciascuna posizione dell'array:ValutaStringa, ValutaFormat, NegCurrFormat, MilleSeparator, DecimalSeparator e ValutaDecimals.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top