So for an example i have a real number let's say 17.4578 but i want to display it in pascal with only two digits after the point so it's 17.45. What do i write in my program?
Asked
Active
Viewed 3,179 times
-2
-
1In a console that would be: `WriteLn(AReal:0:2);` – LU RD Jan 05 '17 at 16:25
-
what does the 0 stand for – Aloulou123 Jan 05 '17 at 16:27
-
2@LURD - that would produce `17.46` . Not sure if that's important to the OP. – Jan 05 '17 at 16:28
-
That is the width specifier. – LU RD Jan 05 '17 at 16:28
-
According to Standard Pascal (ISO/IEC 7185:1990) a width specifier must be greater than or equal to one. – Stuart Jan 05 '17 at 23:13
3 Answers
1
Write(17.4578:0:2)
Will display number 17.46
Generally, arguments look like this → Value : field_width : decimal_field_width
For more info click here
1
This would work. However, if this is the last line of code always remember a readln at the end.
Writeln(17.4578:0:2)
This would lead to 17.46 because it rounds up as it is followed by a 7.
Hope this helps

Dajan3
- 23
- 5