When a floating-point number gets printed, the binary floating-point representation is converted back to decimal. These decimal numbers are displayed in either the format you specify with printf(), or the current output format for numbers (see $# if you use print. $# has a different default value in Perl5 than it did in Perl4. Changing $# yourself is deprecated.This affects all computer languages that represent decimal floating-point numbers in binary, not just Perl. Perl provides arbitrary-precision decimal numbers with the Math::BigFloat module (part of the standard Perl distribution), but mathematical operations are consequently slower.
To get rid of the superfluous digits, just use a format (eg, printf("%.2f", 19.95)) to get the required precision. See Floating-point Arithmetic.
stephen
In reply to (stephen) Re: Strange (rounding?) problem
by stephen
in thread Strange (rounding?) problem
by gildir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |