?
Solved

Handling extremely large numbers with PHP

Posted on 2010-11-20
2
Medium Priority
?
249 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 2000 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

764 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