How to hide decimals in pascal?

Asked

Viewed 16 times

1

I’m making a currency converter and I’m having trouble with the decimals, for example: "$1.0 equals R$ 0.18248175182481752"

I would like to know how to hide the decimals from the second house.

The code is as follows::

uses crt, Graph;
var valorA, valorB, op:Real;

Procedure dolarToReal;
begin

ClrScr;
WriteLn('Digite o valor em dólares: ');
ReadLn(valorA);

valorB := (valorA * 5.48 );
ClrScr;

WriteLn('R$ ', valorA, ' é igual à $ ', valorB);
readln();


end;


Procedure realToDolar;
begin

ClrScr;
WriteLn('Digite o valor em reais: ');
ReadLn(valorA);

valorB := (valorA / 5.48 );
ClrScr;

WriteLn('$', valorA, ' é igual a R$ ', valorB);
readln();

end;


Procedure menu;
begin


WriteLn('1 - Real > Dólar');
WriteLn('2 - Dólar > Real');
ReadLn(op);

if op = 1 
 then
  begin 
  
  realToDolar
  
  end;
if op = 2 
 then
  begin
  
  dolarToReal
  
  end;



end;

begin
  
  textColor(Black);
  textBackground(White);
  ClrScr;

  menu
  
 
end.

1 answer

1


Just add :0:2 to the final result:

WriteLn('$', valorA, ' é igual a R$ ', valorB:0:2);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.