floating point issue?

K

kevin0051

I made a perl program as follows.

-----------------
$AAA = 4.31;
$AAA *= 100;
printf ("%f\n", $AAA);
printf ("%d\n", $AAA);
----------------

The output of this program is
431.000000
430

I don't know why the second output is 431 instead of 431.
Can anyone help?

Thanks
Kevin
 
J

Jürgen Exner

kevin0051 said:
I made a perl program as follows.

-----------------
$AAA = 4.31;
$AAA *= 100;
printf ("%f\n", $AAA);
printf ("%d\n", $AAA);
----------------

The output of this program is
431.000000
430

I don't know why the second output is 431 instead of 431.

I suppose you meant "430 instead of 431".
Can anyone help?

Yes, among others your teacher for "Introduction into Fundamentals of
Basic Computer Numerics".

For more details please also try
printf("%.20f\n",$AAA);
to force 20 digits after the decimal.

For further explanations please see "perldoc -q 999' or previous
discussions in this NG about this ever popular topic.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top