Delphi …. retrive locale format setting
TFormatsettings is record type in Delphi which is used to get or set local information’s like DateTimeFormat, CurrencyFormat, DecimalSeparator etc. wich is declared in System.SysUtils.
For Example you need to retrive your current DecimalSeparator:
1 2 3 4 5 6 7 |
procedure TForm1.Button1Click(Sender: TObject); var fs: TFormatSettings; begin GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, fs); ShowMessage('Actual decimalseparato is:' + fs.DecimalSeparator); end; |
If you need to force some local settings for conversions you can do for example:
1 2 3 4 5 6 7 8 9 10 11 |
procedure TForm1.Button1Click(Sender: TObject); var myMoney : String; FS : TFormatSettings; myMoneyFloat: Extended; begin myMoney := '100000,66'; FS.DecimalSeparator := ','; myMoneyFloat := StrToFloat(myMoney,FS); ShowMessage('Your actual balance:' + myMoneyFloat.toString); end; |
If you want to change only one setting, starting from a particular configuration you can use the “create” constructor like:
1 2 3 4 5 6 7 8 9 10 11 |
procedure TForm1.Button1Click(Sender: TObject); var myMoney : String; FS : TFormatSettings; myMoneyFloat: Extended; begin FS:= TFormatSettings.Create('en-US'); myMoney := '100000.66'; myMoneyFloat := StrToFloat(myMoney,FS); ShowMessage('Your actual balance:' + myMoneyFloat.toString); end; |