Re: Re: Bad PHP error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, that big number is not converted as a string and printed this way, or
I am missing something.

Here is an example:

<?php
$var = 1000000000000;
//Here I have also tried inserting $var = (string) $var;
echo "$var";
?>

This prints:

1E+012

and... not 1000000000000 as it should.

I have first tried just echo $var, but I thought that maybe if I put it
between quotes, it will be printed right, but...

Thank you.

Teddy

----- Original Message ----- 
From: "M. Sokolewicz" <tularis@xxxxxxx>
To: <php-general@xxxxxxxxxxxxx>; "Octavian Rasnita" <orasnita@xxxxxx>
Sent: Saturday, November 27, 2004 11:08 PM
Subject: Re:  Re: Bad PHP error


Marek Kilimajer wrote:

 > This would be for unsigned integers. PHP knows only signed integers,
 > however. So the limit is 2147483648

Good point :)

When you're outputting it, PHP will convert it back to a string, using
the normal integer representation (which is stored aswell). So that
should be fine ;)

- Tul

Octavian Rasnita wrote:

> Ok, I understand. But what can I do if I want to print big numbers like
123
> billion? (but real numbers, not those written with the "E" letter in them?
>
> Is this possible with PHP or I need to do it with another language?
>
> Thank you.
>
> Teddy
>
>
> From: "M. Sokolewicz" <tularis@xxxxxxx>
>
>
> Octavian Rasnita wrote:
>
>
>>Hi all,
>>
>>I have tried the following script:
>>
>>$val = 10000000000;
>>if (is_int($val)) {
>>echo $val;
>>}
>>else {
>>echo "$val is not an integer\n";
>>}
>>
>>The answer is:
>>
>>10000000000 is not an integer.
>>
>>Why does this happen? I use PHP 5.
>>
>>Isn't PHP able to work with values like 10 billion?
>>
>>Do I need to use a certain special class for dealing with big numbers? How
>>can I use that class?
>>
>>Thank you.
>>
>>Teddy
>
> reply it's treated as a double since integers have a max value of (-2e32
> +1 up to) 2e32-1, which is 4,294,967,296 (4 billion and some). However,
> you shouldn't really see any difference in working, it's just treated as
>   a double inside (a double float, that is). Which means it'll be
> written like 1.0e10 internally
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux