big numbers

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Dave2000
Forum Contributor
Posts: 126
Joined: Wed Jun 21, 2006 1:48 pm

big numbers

Post by Dave2000 »

If i want to insert a number >= 1 trillion into a MySQL database table, what data type must I have the field as? For example, if the number is 1 trillion, this is thought of by PHP as 1E+12, and so is inserted into the database as "1". I hope you understand the question...

Thank you

Shears :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

BIGINT

PHP does not handle integers above just over 2 billion (excluding custom builds and 64-bit platforms). If you want to handle large numbers use the gmp and bc extensions.
Dave2000
Forum Contributor
Posts: 126
Joined: Wed Jun 21, 2006 1:48 pm

Post by Dave2000 »

Hello feyd . Thank you for your reply. Sorry, maybe I didn't explain myself properly...

For example, from my script, a number 1.4086919015E+12 is calculated. The problem I am having it inserting this number into the database. Is it possible to force PHP not to return the value in scientific form? I beleive if the number wasn't in scientific form it would insert correctly. This page seems to suggest an unsigned BIGINT column type can hold a value up to 18446744073709551615. Are you saying that if I use the gmp and bc extensions, I can calculate the 1.4086919015E+12 number NOT in scientific form?

Shears
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP cannot natively support such large numbers. It's a 32 bit application. Your result is beyond that possible integer size which results in a floating point number. Floating point allows for a greater range, but less accuracy. GMP and BC are the only solution for keeping calculations looking normal as they use strings for transport.
Post Reply