How to convert a string number to integer

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

leovipin1
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Oct 15, 2012 1:37 pm

How to convert a string number to integer

Postby leovipin1 » Mon Oct 15, 2012 1:44 pm

Hi,

I would require help to convert a string number to integer but the value must remain same. For ex:

Code: Select all

$str="20121016001";
$num=(int)$str;
echo $num;


This above prints 2147483647. But I want to print the exact value as entered in $str variable but should be of integer type.

Thanks in advance,

Regards,
Vipin

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to convert a string number to integer

Postby seandisanti » Mon Oct 15, 2012 1:57 pm

Use a data type large enough to hold the number and you won't have a problem. For int your threshold is around 2 billion. if you use float or double, you expand the size of the container and it works properly.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest