Re: fractional cents

"A. Pagaltzis" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <20040420002619.GA7491@klangraum>
* Bernie Cosell <[email protected]> [2004-04-19 23:32]:
> I'll confess that I took the coward's way out:
> 
>    $money = sprintf "%7.3f", $amt;
>    $money =~ s/0$// ;
>

Doh. My own code was needlessly complex because I was working
from the assumption that there may be no fractional part at all,
in which case your approach would potentially be dangerous, as it
doesn't only chop 1.230 into 1.23, it would also happily chop 10
to 1. Oops. Well, "oops" if it ever got such input, but I
overlooked the fact that the printf format in use guarantees the
presence of a fractional part.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.