DrStrangeLove
DrStrangeLove

Reputation: 11557

What does this Pascal syntax mean

Here's this code:

for i:= 1 to n 
do Write(a[i]:6:2);
Writeln; 

For loop outputs data from array..

Please, help - What does :6:2 in Write() mean?

Thanks in advance!

Upvotes: 0

Views: 1448

Answers (3)

kd4ttc
kd4ttc

Reputation: 1185

The spec x:n:m means a field width of n and m decimal places. It will be formatted as a real. If x=17.8 then x:6:2 comes out as " 17.80". Note that it is one leading space and that it is right justified. If m is 0 then no decimal point and no trailing digits. If you have x:n as the format you get scientific notation in a field width of n.

Also, n and m can be integer variables, so the field widths and decimal points can be changed during execution.

Upvotes: 0

Dominik
Dominik

Reputation: 3362

this will format your output in case you have a number/decimal in a. If i remember correctly, in your case, the 2 means the max number of decimal places below 0 and the 6 the maximum digits printed for numbers above 0.

HTH Dominik

Upvotes: 0

Ray
Ray

Reputation: 396

It's output formatting. This means use 6 digits for output with 2 decimal positions

Upvotes: 4

Related Questions