| core_util

# Class: Bs_Number Source Location: /core/util/Bs_Number.class.php
### Class Overview
    Bs_Object
       |
       --Bs_Number
This static class provides many useful number methods. #### Author(s): andrej arn <at blueshoes dot org> #### Version: 4.3.$Revision: 1.4 $ $Date: 2003/11/12 22:34:55 $ #### Copyright: blueshoes.org | ### Methods Bs_Number decimalToFraction gcd hexToBin isNumericLarge roundNoTrim
### Inherited Variables | ### Inherited Methods #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 19] This static class provides many useful number methods. no dependencies here. #### Tags:
version: | 4.3.$Revision: 1.4 $ $Date: 2003/11/12 22:34:55 $
copyright: | blueshoes.org
author: | andrej arn <at blueshoes dot org>
status: | experimental
[ Top ] ### Class Methods ### constructor Bs_Number [line 25]
`Bs_Number Bs_Number( )`
constructor. [ Top ] ### method decimalToFraction [line 179]
`void decimalToFraction( mixed $number)`
A simple function that converts numbers with decimal remainders to numbers with fractional remainders. example: decimalToFraction(1.2) => 1 1/5 #### Tags:
copyright: | gpl J.A. Greant (zak@nucleus.com) Version 1: June 9, 2000 http://www.zend.com/codex.php?id=175&single=1
[ Top ] ### method gcd [line 165]
`int gcd( int $a, int $b)`
A simple function that finds the Greatest Common Denominator for two numbers. example: gcd(40, 12) => 4 #### Tags:
return: | greatest common denominator
copyright: | gpl J.A. Greant (zak@nucleus.com) Version 1: June 9, 2000 http://www.zend.com/codex.php?id=174&single=1
#### Parameters:
int | $a | first number
int | $b | second number
[ Top ] ### method hexToBin [line 147]
`string hexToBin( string $source)`
easy function to convert hexdata to bindata. It's very good to use decode mcrypt hexdata. example: $hexdata="FFF0A025ef"; $bindata = hex2bin($hexdata); #### Tags:
return: | bin
copyright: | dziadek@xcom.pl http://www.zend.com/codex.php?id=408&single=1
#### Parameters:
string | $source |
[ Top ] ### method isNumericLarge [line 97]
`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:
deprecated: | use PHP's is_numeric.
#### Parameters:
mixed | $param |
[ Top ] ### method roundNoTrim [line 114]
`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:
return: | (!!!)
#### Parameters:
mixed | $value | (double, int or something numeric)
int | $precision | (default is 2)
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:12:07 +0100 by phpDocumentor 1.2.3