Display currency as different currency type ($10 -> R10)

Viewed 123

how does one change the value of the type of currency? I am getting $ for my currency when i need R.

procedure TfrmFinal.addSubtractTotal; 
var 
  total: currency; 
begin 
  total := 0; 
  frmDataModule.tblpins.First; 
  while not frmDataModule.tblpins.Eof do 
  begin 
    total := total + 
      frmDataModule.tblpins.FieldByName('qty').AsInteger * 
      frmDataModule.tblpins.FieldByName('price').AsCurrency; 
    frmDataModule.tblpins.Next; 
  end; 
  totalAmmountLabel.Text := total.ToString; 
end;
1 Answers

There are a few ways to solve this. Unfortunately, I don't have the TCurrencyHelper, but here are a few other options:

procedure TForm1.Button1Click(Sender: TObject);
 var Total: Currency;
begin
  Total := 155;
  var FormatSettings := TFormatSettings.Create(7177); //LCID for South Africa, MAY not be necessary if that is the local setting on the machines you are supporting
  button1.Caption := FloatToStrF(Total, ffCurrency, 15,2, FormatSettings);
  button1.Caption := FormatCurr('', Total, FormatSettings);
  button1.Caption := CurrToStr(Total, FormatSettings);
  button1.Caption := CurrToStrF(Total,ffCurrency,2,FormatSettings);
end;

All of them are slightly different. My preference would be CurrToStrF (which then calls FloatToStrF), but that is just out of habit.

Related