* Keith C. Ivey [EMAIL PROTECTED] [2004-04-22 14:48]:
Math won't work, because floats aren't exact.
Actually, that is a point I meant to make somewhere in this
thread.
When you're dealing with money, it's better to use cents (or
tenths or hundredths of cents) as a unit, rather than dollars.
You
On Mon, Apr 26, 2004 at 06:49:52AM +0200, Pense, Joachim wrote:
A. Pagaltzis [mailto:[EMAIL PROTECTED] wrote:
When you're dealing with money, it's better to use cents (or
tenths or hundredths of cents) as a unit, rather than dollars.
You can then use integer math. This gets you around all
Ronald J Kimball wrote:
But then you still have the issue of marking the difference between 257
cents and 257.0 cents.
Of course. But that's much better than marking the difference between
2.57
dollars and 2.56984013 dollars, wouldn't you agree?
I don't think it is the
Bernie Cosell [EMAIL PROTECTED] wrote:
...
And so for 'normal prices' I want them printed normally, and only
the fractional-prices should print with the extra digit...
O.k., so, if the representation with three decimal places would
have a zero in the last place, chop off the zero, right?
It's
. 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
* 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?
* Bernie Cosell [EMAIL PROTECTED] [2004-04-22 00:02]:
On 21 Apr 2004 at 22:55, A. Pagaltzis wrote:
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
A. Pagaltzis [EMAIL PROTECTED] wrote:
It's not shorter or more obvious I'm afraid, just a little more
correct.
The trouble I'm having with this problem is knowing what is
correct. It seems to me that the precision desired should
depend on context, and nothing else. And that being the case...
Bernie,
there's the fairly awful:
sprintf ($amt =~ /\.\d\d\d/? %7.3f: %7.2f), $amt
Woops. ^^^
I think you meant :
sprintf ($amt =~ /\.\d\d\d/? %7.3f: %7.2f , $amt)
There *must* be some really sneaky/clever way to switch the
* 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
Right off the bat I thought of %g, but that doesn't really help:
* Quantum Mechanic [EMAIL PROTECTED] [2004-04-19 23:09]:
--- A. Pagaltzis [EMAIL PROTECTED] wrote:
my $amt_str = sprintf %7.3f, $amt;
for($amt_str) { chop if /\.\d\d0\z/ }
Why would you do for..chop when you could do s///?
You're using an re either way?
;)
=
On 19 Apr 2004 at 20:18, McGlinchy, Alistair wrote:
there's the fairly awful:
sprintf ($amt =~ /\.\d\d\d/? %7.3f: %7.2f), $amt
Woops. ^^^
I think you meant :
sprintf ($amt =~ /\.\d\d\d/? %7.3f: %7.2f , $amt)
There *must*
12 matches
Mail list logo