Question

Lets say I have a 10,000 digit number in my database...

This would be laggy for the viewer if it was echoed out.

Is there a way to display only like 100 (the first 100)? Digits?

-Either using php, or (Pref.) using MySQL to only get the first 100...

Was it helpful?

Solution

Before you can display such a number, MySQL would require such a large number to be stored as a double or you could store it as a string. Actually, doubles only allow about 308 digits. If you stored it as a string, you could convert it to scientific notation using substring and concatenation (with the dot) with whatever precision you like. You could count the length of the string to get the exponent. Of course you can't use the database to do math.

Why would you need this kind of precision?

OTHER TIPS

Why are you using PHP to store such numbers? What kind of website needs that feature?

You may want to use Perl, Python, or Ruby for that kind of thing. Python has built-in support for large numbers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top