* Smylers <[EMAIL PROTECTED]> [2004-04-22 13:43]:
> > ... 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.

Yep, you're right.

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

Another good point. And at this point we're in a position where
no printf format will help; there's no way to get printf to round
the way we'd want to. Basically at this point comes down to
writing a custom stringification.. or looking for one on CPAN, at
least.

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."

Reply via email to