BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/util/Bs_Number.class.php
BlueShoes Application Framework - util

Bs_Number

Bs_Object
   |
  +-- Bs_Number

This static class provides many useful number methods.

 

public class Bs_Number extends Bs_Object

This static class provides many useful number methods.
no dependencies here.@status experimental

Authors
Version4.0.$id$
Copyrightblueshoes.org

 

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

string

roundNoTrim(mixed $value, [ integer $precision ])

rounds a given number to the specified number of digits after the dot.
string

hexToBin(string $source)

easy function to convert hexdata to bindata.
int

gcd(int $a, int $b)

A simple function that finds the Greatest Common Denominator for two numbers.
void

Bs_Number()

Warning: documentation is missing.

Private Method Summary

bool

isNumericLarge(mixed $s)

there is a problem with php's is_numeric: it's limited to 16 digits. a
void

decimalToFraction( $number)

A simple function that converts numbers with decimal remainders to numbers with fractional remainders.
void

is_numeric( $n)

Warning: documentation is missing.
void

is_num()

Warning: documentation is missing.

Private Constant Summary

BS_NUMBER_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

roundNoTrim

public string roundNoTrim( mixed $value, [ integer $precision ] )

  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.4THIS: round(5.4, 2) => 5.40

Parameter
mixed $value
(double, int or something numeric)
integer $precision = >>2<<
(default is 2)
Returns string

(!!!)


hexToBin

public 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);

Parameter
string $source
Returns string

bin

Copyright dziadek@xcom.pl http://www.zend.com/codex.php?id=408&single=1

gcd

public int gcd( int $a, int $b )

  A simple function that finds the Greatest Common Denominator for two numbers.
example: gcd(40, 12) => 4

Parameter
int $a
first number
int $b
second number
Returns int

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

Bs_Number

public void Bs_Number( )

 

Warning: documentation is missing.

Returns void


Private Method Details

isNumericLarge

private bool isNumericLarge( mixed $s )

  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 athttp://www.php.net/manual/en/function.is-numeric.phpsome 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 goodfor 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+0392)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) andadd the characters '-.+E' to the allowed ones. but it could be interpreted wrong in some cases, likea 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.

Parameter
mixed $s
Returns bool


decimalToFraction

private void decimalToFraction( $number )

  A simple function that converts numbers with decimal remainders to numbers with fractional remainders.
example: decimalToFraction(1.2) => 1 1/5

Parameter
$number
Warning: documentation is missing.
Returns void

Copyright gpl J.A. Greant (zak@nucleus.com) Version 1: June 9, 2000 http://www.zend.com/codex.php?id=175&single=1

is_numeric

private void is_numeric( $n )

 

Warning: documentation is missing.

Parameter
$n
Warning: documentation is missing.
Returns void


is_num

private void is_num( )

 

Warning: documentation is missing.

Returns void


Private Constant Details

BS_NUMBER_VERSION

define( BS_NUMBER_VERSION, >>4.0.$x$<< )
Case: default: case sensitive




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta