Page 1 of 1

echo'ing large integers produces scientific notation

Posted: Wed Aug 16, 2006 10:47 pm
by mu-ziq
I want to output large integers that I get from database to screen but they always come out in scientific notation.

Code: Select all

$n = 10000000000000000000000000000;
echo 'number: '.$n; // outputs "number: 1E+028"

I know that's how php represents long numbers but I want my output to say 10000000000000000000000000000 not 1E+028.

I'm wondering if there is a built in function or a way that will automatically convert (scientific float) -> (normal string) or if I have to write one myself.

Thanks a lot.

Posted: Wed Aug 16, 2006 10:54 pm
by feyd
PHP does not process large integers natively. They are automatically converted to floating point after you reach a certain threshold. What that is, depends on the build you run it on. Use GMP or BC instead.

Re: echo'ing large integers produces scientific notation

Posted: Thu Aug 17, 2006 1:13 am
by daedalus__
mu-ziq wrote: I'm wondering if there is a built in function or a way that will automatically convert (scientific float) -> (normal string) or if I have to write one myself.
$n = '10000000000000000000000000000';

If the database stores them as integers maybe you could use mysql to cast them so they come back as strings or something?

I don't think it has to be as complicated as a function but I've never had to deal with this sort of thing so I could be wrong.