[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Handling extremely large numbers with PHP

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

649 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