How to represent currency in Pascal

1 Answer

0 votes
{---------------------------------------------------------
  Description:
    Demonstrates how to represent and display currency
    values in Free Pascal using the Currency type.
---------------------------------------------------------}

program CurrencyExample;

{$mode objfpc}

var
  price, taxRate, taxAmount, total: Currency;

begin
  { Assign values }
  price := 199.99;
  taxRate := 0.17;  { 17% }

  { Calculate tax and total }
  taxAmount := price * taxRate;
  total := price + taxAmount;

  { Output with $ and % signs }
  writeln('Price: $', price:0:2);
  writeln('Tax Rate: 17%');
  writeln('Tax Amount: $', taxAmount:0:2);
  writeln('Total: $', total:0:2);
end.



(*
run:

Price: $199.99
Tax Rate: 17%
Tax Amount: $34.00
Total: $233.99

*)

 



answered 4 hours ago by avibootz
...