Re: fractional cents

"A. Pagaltzis" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <20040420003321.GB7491@klangraum>
* Bernie Cosell <[email protected]> [2004-04-19 17:37]:
> So: what I want is something to format money correctly, whther
> it is fractional or not.  there's the fairly awful:
> 
>      sprintf ($amt =~ /\.\d\d\d/? "%7.3f": "%7.2f"), $amt
> 
> Not much better and a ton more dangerous [due to rounding]:
>      sprintf (int($amt/100) == $amt/100 ? ...etc

I am stupid and slow. Of course it can be done with math, and
easily too:

    sprintf ( ( $amt * 1000 ) % 10 ? "%7.3f" : "%7.2f " ), $amt

-- 
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.