Page 1 of 1

convert form input into integer

Posted: Tue Sep 13, 2005 8:44 am
by bytte
I have an input textfield in my html form.
When submitted, the contents of that field should be made an integer.

(The input field allows for 11 characters, so I had to use bigInt in MySql.)

doing:

Code: Select all

(int)$_POST['number'];
creates an wrong integer.

What should I do? I think it has something to do with the 11 character length of the value inputted.
Everything below 11 characters is converted without any problem by the above method.
But as soon as I try to convert an 11 character value it fails.

Any idea?

Posted: Tue Sep 13, 2005 8:47 am
by feyd
PHP has a built-in upper limit to how long a basic integer can go. On most machines, it's 2,147,483,647. After that it'll wrap around to negative numbers.

Look into using GMP for larger integer math.