Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How pascal assigns a real number with two decimal places to a string
How pascal assigns a real number with two decimal places to a string
For example, the variable a=2.537256,

After retaining two decimal places, it is 2.54.

Then we can use the round function in pascal.

For the convenience of extraction, we perform the following operations c: = round (a *100) mod100;

(c is an integer variable)

Then use STR () function to convert.

The code (pascal language) is as follows.

(This code has been compiled by free pascal and verified manually. )

defined variable

A: True;

c:longint;

S: string;

begin

Reformulated as (a);

c:= round(a * 100)mod 100;

str(c,s);

Writing content;

End.

For example, enter 5.738.

Output 74

Do you understand?

I hope this answer is helpful to your study.