ok, im making a basic program in pascal. like a text based calculator (i dont know how to make GUIs) so lets say i have a peice of code like this:

``````program test;
var
A,B,C:real;

begin
writeln('enter the first number');
writeln('enter the second number');
C:=A/B;
End.``````

when i do this, it displayes the decimel in scientific notation (EX 50.00 woiuld be 5.000000000E+001) witch alot of people dont know how to read scientific notation. is there anyway to convert this into a decimel that people are used to like 104.00 ?

Yes. For some oddball reason it isn't in any of the Delphi docs that I've ever seen, but you can specify width and precision for floating point variables:

``````var foo: real = 41.99;
begin
writeln( 'The answer is ', foo:0:1 )
end.``````

Notice how it will automatically …

Ah. It works because it is standard Pascal... :)

All 7 Replies

Yes. For some oddball reason it isn't in any of the Delphi docs that I've ever seen, but you can specify width and precision for floating point variables:

``````var foo: real = 41.99;
begin
writeln( 'The answer is ', foo:0:1 )
end.``````

Notice how it will automatically round for you. The second number is the precision field, which specifies the number of digits to have after the decimal point. The first number is the width field. You should generally leave it as zero.

Hope this helps.

[EDIT] Oh yeah, you can use variables for the width and precision fields too...

thx! i wasnt using delphi, but it still worked in pascal.

Ah. It works because it is standard Pascal... :)

hi
if pass and username good display OK
else
using while loops

if pass and username good display OK
else
using while loops

2. Post what you've done to try to do the HW assignment. Then we'll help.

``````var a, b, s:    real;
begin
write('enter the first number: ');    read(a);
write('enter the second number: ');    read(b);

s:=a / b;