TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   How to count Integer lenght (http://www.talkphp.com/absolute-beginners/3330-how-count-integer-lenght.html)

Yoosha 09-06-2008 03:35 PM

How to count Integer lenght
 
Hi,
How can i count an Integer lenght?
Example: $X= 8766435322364576;

Also dif. between strval($X) V.S. (string)($X)?
Regards.

xenon 09-06-2008 04:57 PM

You can use strlen.

The only difference is speed there. (string) is an explicit cast (aka a language construct), whereas strval is a function, and therefore, is more memory consuming.

Yoosha 09-07-2008 10:27 AM

Xenon: You can use strlen.

No i can't use that. This is for String, not Integer.
StringLength no IntegerLength!
Test this:

$X= 8766435322364545664565464654676;
echo(strlen($X));

Yoosha 09-12-2008 05:53 PM

I found.
Finded:

function _Number_Length($Int_Input)
{
$_Int_Output= number_format($Int_Input, 0, '.', '');
return((integer)strlen($_Int_Output));
}

Resolved.

xenon 09-12-2008 06:49 PM

Ok then, just convert the int to a string before passing it to strlen. Aka:

PHP Code:

echo strlen((string) 293898239382); 


Yoosha 09-13-2008 05:25 AM

Quote:

Originally Posted by xenon (Post 18346)
PHP Code:

echo strlen((string) 293898239382); 


WOW ^^:-D :)))))))))))

Salathe 09-13-2008 11:44 PM

Try: echo strlen((string) 12345678901234567890);

Kalle 09-14-2008 01:04 PM

Quote:

Originally Posted by Yoosha (Post 18264)
Xenon: You can use strlen.

No i can't use that. This is for String, not Integer.
StringLength no IntegerLength!
Test this:

$X= 8766435322364545664565464654676;
echo(strlen($X));

Its because the number is higher than PHP_INT_MAX, you need to cast it to a string like the others said before it will work :)


All times are GMT. The time now is 10:17 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0