A. Pagaltzis writes:

> * 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
> 
> ... it can be done with math, and easily too:
> 
>     sprintf ( ( $amt * 1000 ) % 10 ? "%7.3f" : "%7.2f " ), $amt

That isn't right: for $amt = 1.2306 it yields 1.23, while the original
yields the correct 1.231.

What about for values such as 1.2304?  Again the 'modulus' version
yields 1.23, whereas the 'regex' version this time gives 1.230.  It's
less clear which is correct for this case, but I'd think the latter on
the basis that the amount does have fractional cents.

Smylers

Reply via email to