Two digits after the decimal point in a real number in Pascal

3.8k Views Asked by At

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?

3

There are 3 best solutions below

0
On BEST ANSWER
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

0
On

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

0
On

Use :0:2 at the end of Real number:

writeln(17.4578:0:2)