fractional cents

"Bernie Cosell" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Organization Fantasy Farm Fibers
Message-ID <[email protected]>
I'm fiddling with a super-tiny bit of code where just for obscurity's 
sake, I feel like doing something tricky.  A prog I've been working on 
has suddenly grown the need for fractional cents in its money dealings, 
*sometimes*.  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

There *must* be some really sneaky/clever way to switch the format from 
two placed to three places just when I need it....

  /Bernie\

-- 
Bernie Cosell                     Fantasy Farm Fibers
mailto:[email protected]     Pearisburg, VA
    -->  Too many people, too few sheep  <--
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.