Solved

Handling extremely large numbers with PHP

Posted on 2010-11-20
2
248 Views
Last Modified: 2012-05-10
I am creating a calculator app that needs to be able to handle large numbers accurately. Since integers larger than 2147483647 can't be handled by PHP, and floats have an accuracy issue:

echo floor((.7+.1)*10) //Outputs 7

Open in new window


I need another solution. Is there any way to ensure accuracy with floats or another way to do math with php? Although I'd rather not use JS, as this means that someone can copy my processer, can JS handle large numbers?
0
Comment
Question by:cloud-9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
armchang earned 500 total points
ID: 34180475
Hi,

For some reason, there are two standard libraries in PHP handling the arbitrary length/precision numbers: BC Math and GMP. I personally prefer GMP, as it's fresher and has richer API.

Based on GMP I've implemented Decimal2 class for storing and processing currency amounts (like USD 100.25). A lot of mod calculations there and tried with very large numbers w/o any problems.

Go to GMP
Go to BC Math

0
 
LVL 3

Author Closing Comment

by:cloud-9
ID: 34183347
Thank-you for your quick response. This will work.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question