How to format decimal in Pascal

1 Answer

0 votes
program FormatDecimalExample;
var
  number: Real;
begin
  number := 123.456789;
  
  // Format the number to 2 decimal places
  writeln('Formatted to 2 decimal places: ', number:0:2);
  
  // Format the number to 4 decimal places
  writeln('Formatted to 4 decimal places: ', number:0:4);
  
  // Format the number to 6 decimal places
  writeln('Formatted to 6 decimal places: ', number:0:6);
end.



(*
run:

Formatted to 2 decimal places: 123.46
Formatted to 4 decimal places: 123.4568
Formatted to 6 decimal places: 123.456789

*)

 



answered May 6, 2025 by avibootz
...