bool isNumericLarge(
mixed
$s, mixed
$param)
|
|
there is a problem with php's is_numeric: it's limited to 16 digits. a 17 digit number/string would be interpreted as not numeric. :(
there are many different solutions posted at http://www.php.net/manual/en/function.is-numeric.php
some are just there for ppl still using php3 cause is_numeric() doesn't exist there. some also try to work around the 16 digits limitation. so let's see which one is good for us:
1) ymoi@netcourrier.com 02-Aug-2001 04:29 To test if a variable is numeric or not : $temp = (float) $var; $temp = (string) $temp; if ($temp<> $var) { //var is not numeric} => FAILED with a 40 digit number; 1234567890123456789212345678931234567894 != 1.2345678901235E+039
2) uioreanu@hotmail.com 31-Jul-2001 06:55 Or something like: if (((int) $sWord)== $sWord) { // numeric only word // ... } => FAILED with '1 23' and 'abc'.
3) php@starnet.com 19-Jun-2001 04:30 In PHP3, how about this? function is_numeric($n) { return(0 + $n == $n); } => FAILED with '1 23' and 'abc'.
4) ealma@hotmail.com 18-May-2001 12:02 Here is some code that will detect large values for numeric and for PHP3. function is_num(s) { v = true; for i = 0 to strlen(s) { if (ord(substr(s,i,1)) < 48 || ord(substr(s,i,1)) > 57) v = false; } return v; } => FAILED with -123.45E293, '-123.45E293' (as string or number).
5) ASkwar@DigitalProjects.com 26-May-2001 06:56 Someone wanted to know how to check if a val is numeric in PHP3. Here's my take: $val = -123.45E293; $match = '^-?\d+(?:\.\d+)?(?:[Ee]-?\d+)$'; if (preg_match('|' . $match . '|', $val)){ echo $val . ' is a number!'; } else { echo $val . ' is not a number!'; } => FAILED with 123, 1234567890123456789212345678931234567894, -123.45E293 (if not written as string).
after all that i can see that only a regexp could do the job 100% correct. we could use version 4) and add the characters '-.+E' to the allowed ones. but it could be interpreted wrong in some cases, like a string 'E123' or '1-1' or '9+9+9+9'.
i've requested help from take 5) (ASkwar@DigitalProjects.com) so let's see what we get.
feel free to replace it with another one. make sure it returns a real bool, thanx.
Tags:
Parameters:
string roundNoTrim(
mixed
$value, [int
$precision = 2])
|
|
rounds a given number to the specified number of digits after the dot.
this method uses php's round() with the following difference: PHP: round(5.4, 2) => 5.4 THIS: round(5.4, 2) => 5.40
Tags:
Parameters: