EHS Blog
Home  
 

 
Categories


Web Hosting
Website Design
PHP
Perl
JSP
   

 
Archives

No Records !!!
   
 

 
Making $$$ with PHP
at 2007-08-12 15:10:22

Not exactly what you thought reading the title, sorry :) Just wanted to write about the topic discussed elsewhere - how one could do money calculations with PHP? PHP has no BCD type and no arbitrary precision float type either. And for money calculations is it important to have it very precise - accountants can not allow even single penny to slip by (remember the plot of the Office Space movie? ;)
So, using regular floats/doubles is not good in this case - for starters, there’s no precise representation for number as simple as 0.1! So if you make a lot of calculations with such numbers errors would creep in. Now the question is what could be done about it?

One solution is to make all calculations in units like one hundredth or thousandth of a cent and make everything integer, using arbitrary-precision integers like in GMP and then when printing it just shift the point and cut the extra digit whenever needed. This might be good enough if we knew how precise we should get.

Even better would be to have a type that combines arbitrary-precision integer and decimal point position, like Java does. I wonder if something can be done with GMP. It does have arbitrary precision floats, but I’m not sure it would fit.

Or, maybe there’s some other, better solutions for this? I don’t have much experience with money calculations and problems and solutions in that area…



Blog Source - http://php100.wordpress.com/feed/
 


Last 10 Posts
   
  - Java University: Building Dynamic Web Sites with Ajax and Dojo

  - JavaFX -- Simplifying UI for Content Developers

  - Simplify App Development with The Swing Application Framework

  - Configuring NetBeans for the Java Persistence API

  - The Swing Application (Un)Framework

  - POJOs on the Desktop with the Java Persistence API

  - Swing Application Framework Architecture

  - Swing Application Framework: Lifecycle Events

  - Core Java Technologies Tech Tips

  - Managing resources in the Swing Application Framework (JSR 296)

   


Check Out Amazon