Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 2/Formatting output: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
112C - Formatting Output (author: Tao Yue, state: unchanged)
22
33Formatting output is quite easy. For each identifier or literal value on the argument list, use:
44
55``` pascal
66Value : field_width
77```
88
99The output is right-justified in a field of the specified integer width. If the width is not long enough for the data, the width specification will be ignored and the data will be displayed in its entirety (except for real values — see below).
1010
1111Suppose we had:
1212
1313``` pascal
1414write ('Hi':10, 5:4, 5673:2);
1515```
1616
1717The output would be (that's eight spaces before the Hi and three spaces after):
1818
19-`        Hi   55673`
19+```
20+ Hi 55673
21+```
2022
2123For real values, you can use the aforementioned syntax to display scientific notation in a specified field width, or you can convert to fixed decimal-point notation with:
2224
2325``` pascal
2426Value : field_width : decimal_field_width
2527```
2628
2729The field width is the total field width, including the decimal part. The whole number part is always displayed fully, so if you have not allocated enough space, it will be displayed anyway. However, if the number of decimal digits exceeds the specified decimal field width, the output will be displayed rounded to the specified number of places (though the variable itself is not changed).
2830
2931``` pascal
3032write (573549.56792:20:2);
3133```
3234
3335would look like (with 11 spaces in front):
3436
35-`           573549.57`
37+```
38+ 573549.57
39+```
3640
3741---
3842*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 2/Formatting output", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history