tags:

views:

40

answers:

2

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...

A: 

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.

mcandre
One: I only know php :)Two: :(
James Rattray
Do you know if MySQL can do something like this? -get first 100 or something?
James Rattray
He does not say that he has a website using this feature. Not all PHP apps are websites. Don't take this as much of a critique, because I have no answer at all.
MJB
+1  A: 

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?

SorcyCat
String hmmm ok, but im guerssing theres no mySQL function to just get the first 100 characters? -you would have to use php?
James Rattray
See substring and left - http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
SorcyCat
To be more specific: select left(yourfield,100) as truncated from yourtable
SorcyCat
So example:SELECT * FROM `mytable` WHERE `random field` = '$randomvariable' would become: SELECT left (`mytable`,100) WHERE `random field` = '$randomvariable'?
James Rattray
yes. Did you try it?
SorcyCat