[comp.lang.pascal] format real to output

ZCCBJSB%EB0UB011.BITNET@cunyvm.cuny.edu (Josep Sau B.) (05/02/91)

KHALED BAHGAT asks:

>Is there any developed procedure that would display a real varaiable
>in a non exponential format
>   e.g.
>     Var x : real;
>     Begin
>       x := 1.3;
>       writeln(x);
>     End.
>
> I'd like the output to be 1.3 not in an exponential format.

Take a look in the manual about the output format specifiers for
write and writeln.
You can specify the width of the output field for any variable,
using the colon notation WRITE(aVar:n) where n is a positive integer
(the exact range may be found in the manual).
Moreover, there is another optional format specifier for
real values that allow to truncate the output to a number of digits
after the decimal point, ex. WRITE(aReal:n:d)

The concrete problem you asked for would be coded as
  WRITELN(1.3:3:1)
where the field width specifier includes the decimal point
and the digits after the decimal point.

--Josep sau