Re: fractional cents

"Bernie Cosell" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Organization Fantasy Farm Fibers
Message-ID <[email protected]>
On 21 Apr 2004 at 22:55, A. Pagaltzis wrote:

> * John Douglas Porter <[email protected]> [2004-04-20 08:39]:
> > It seems to me that the precision desired should depend on
> > context, and nothing else.  And that being the case...
> > 
> >   printf $fractional_cents ? '%7.3f' : '%7.sf', $amt;
> > 
> > irrespective of the value of $amt.  Why is this not right?
> 
> What you have written is neutral with regards to the issue I was
> referring to.
> 
> If you do this by looking at $amt, then your method must be
> mathematical, because chopping characters in the string
> representation of the unrounded $amt might occasionally lead to
> results different from what the mathematical method would have
> produced with rounding involved.

Correct, but doesn't "%.Xf" round?  And so running it through the 
(s)printf before you mess with it gets you the desired rounding, doesn't 
it?

As for John's question, it is a matter of significant digits.  When 
you're pricing things, prices are in dollars and cents.... except for 
those few items which are fractional.  I know *I* wouldn't want to see 
every price come out as "$12.750" just because one item is "1.975/gallon" 
or [the actual situation]: "$.995/lb"

And so for 'normal prices' I want them printed normally, and only the 
fractional-prices should print with the extra digit...

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