Hello!
In PHP 5, I use intval() whenever I get numbers as an input. This way, I want to ensure that I get no strings or floating numbers. My input numbers should all be in whole numbers. But when I get numbers >= 2147483647, the signed integer limit is crossed.
What can I do to have an intval() equivalent for numbers in all sizes?
Here's what I want to have:
<?php
$inputNumber = 3147483647.37;
$intNumber = intvalEquivalent($inputNumber);
echo $intNumber; // output: 3147483647
?>
Thank you very much in advance!
Edit: Based on some answers, I've tried to code an equivalent function. But it doesn't work exactly as intval() does yet. How can I improve it? What is wrong with it?
function intval2($text) {
$text = trim($text);
$result = ctype_digit($text);
if ($result == TRUE) {
return $text;
}
else {
$newText = sprintf('%.0f', $text);
$result = ctype_digit($newText);
if ($result == TRUE) {
return $newText;
}
else {
return 0;
}
}
}