|
Posted by Jerry Stuckle on 02/02/08 04:00
larry@portcommodore.com wrote:
> On Feb 1, 8:12 am, The Natural Philosopher <a...@b.c> wrote:
>
>> I put in some checks:
>>
>> echo $sale_price gives me 69.99
>> Echo ($sale_price*100) gives me 6999
>>
>> But printf ("%d",$sale_price*100);
>>
>
> When dealing with financial data is usually good to either truncate or
> round the values before doing much with them. Those hidden decimal
> places will get you - though sometimes you have to work three digits
> out (USPS mailing calculations go deeper).
>
> Family data and accurate money are always two challenges for a
> programmer.
>
Most banks and other financial institutions go at least 4 decimal places
PAST the cents (6 decimal places) at a minimum.
They keep the data to these decimal places, but I think if they need to
pay you (i.e. interest), they truncate the value. But if you need to
pay them, they round the data (or worse yet, ceil it) :-)
The final total for you doesn't change (at least noticeably). But it
does make a difference to them.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|