program FormatDouble;
var
myDouble: Double;
begin
myDouble := 25.0; // This is internally 2.5E+01
Writeln('Default scientific notation: ', myDouble);
// To show as 25.0 (one decimal place, automatic width)
Writeln('Formatted to 1 decimal place: ', myDouble:0:1);
// To show as 25.00 (two decimal places, automatic width)
Writeln('Formatted to 2 decimal places: ', myDouble:0:2);
// To show as 25 (zero decimal places, truncates fraction)
Writeln('Formatted to 0 decimal places: ', myDouble:0:0);
// Example with a number that isn't an exact integer
myDouble := 123.45678;
Writeln('Default scientific notation: ', myDouble);
Writeln('Formatted to 2 decimal places: ', myDouble:0:2); // Output: 123.46 (rounds)
Writeln('Formatted to 4 decimal places: ', myDouble:0:4); // Output: 123.4568
// Example pads with spaces if needed
myDouble := 9.5;
Writeln('Padded with total width 10, 2 dec: ', myDouble:10:2); // Output: 9.50
end.
(*
run:
Default scientific notation: 2.5000000000000000E+001
Formatted to 1 decimal place: 25.0
Formatted to 2 decimal places: 25.00
Formatted to 0 decimal places: 25
Default scientific notation: 1.2345677999999999E+002
Formatted to 2 decimal places: 123.46
Formatted to 4 decimal places: 123.4568
Padded with total width 10, 2 dec: 9.50
*)