You are here: Re: why does 69.99*100=6998? « PHP Programming Language « IT news, forums, messages
Re: why does 69.99*100=6998?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация