Posted by Toby A Inkster on 12/08/07 10:51
Acrobatic wrote:
> This is a simple accounting application, and the code below is checking
> to see if a user's withdraw request is greater than their available
> balance:
To build on Jerry's post, floats are a really bad idea for representing
currencies. They're just too woolly. As PHP doesn't include any fixed-
precision decimal data type, the best option is to represent money as an
integer -- using the smallest unit of currency possible (e.g. cents
rather than euros; pence rather than pounds).
You then reformat it as a price in the larger unit of currency only when
it needs to be displayed.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 21:23.]
Sharing Music with Apple iTunes
http://tobyinkster.co.uk/blog/2007/11/28/itunes-sharing/
[Back to original message]
|