RSI helpers  0.1
RSI helpers
Number Class Reference

Helpers for numbers of all sorts. More...

Static Public Member Functions

static add ($value, $add=1, $base=null, $upper=null)
 Add a value to a non-decimal number. More...
 
static shorthandBytes ($size)
 Returns the size in bytes for shorthand notations (e.g. More...
 
static formatBytes ($size, $decimals=1, $dec_point='.', $thousands_sep=',', $unit_sep=' ')
 Formats a size in bytes to its shorthand format. More...
 
static toRoman ($value)
 Format a number as a Roman number. More...
 
static celsiusToFahrenheit ($value)
 
static fahrenheitToCelsius ($value)
 
static units ($value, $units, $tolerance=0)
 Split a value into different units. More...
 
static fraction ($value, $tolerance=0.000001)
 Turn a decimal number into a fraction. More...
 
static evaluate ($expr)
 Evaluate a mathamatical expression. More...
 

Detailed Description

Helpers for numbers of all sorts.

Definition at line 8 of file Number.php.

Member Function Documentation

◆ add()

static add (   $value,
  $add = 1,
  $base = null,
  $upper = null 
)
static

Add a value to a non-decimal number.

Parameters
string$valueBase value in base $base.
int$addDecimal value to add to $value.
int$baseThe base the $value is in (defaults to 10).
bool$upperConvert the return value to uppercase (only for $base > 10). Auto-detect on null (defaults to true).
Returns
string Value $value with $add added, in base $base.

Definition at line 18 of file Number.php.

◆ celsiusToFahrenheit()

static celsiusToFahrenheit (   $value)
static

Definition at line 79 of file Number.php.

◆ evaluate()

static evaluate (   $expr)
static

Evaluate a mathamatical expression.

Parameters
string$exprMathamatical expression.
Returns
float Answer (throws Exception on error).

Definition at line 130 of file Number.php.

◆ fahrenheitToCelsius()

static fahrenheitToCelsius (   $value)
static

Definition at line 83 of file Number.php.

◆ formatBytes()

static formatBytes (   $size,
  $decimals = 1,
  $dec_point = '.',
  $thousands_sep = ',',
  $unit_sep = ' ' 
)
static

Formats a size in bytes to its shorthand format.

Parameters
int$sizeSize in bytes.
int$decimalsNumber of decimals.
string$dec_pointSeparator for the decimal point.
string$thousands_sepThousands separator.
string$unit_sepSeparator between number and unit.
Returns
string

Definition at line 53 of file Number.php.

◆ fraction()

static fraction (   $value,
  $tolerance = 0.000001 
)
static

Turn a decimal number into a fraction.

Parameters
float$value
float$toleranceTolerance for result.
Returns
array Array with numerator and denominator.

Definition at line 110 of file Number.php.

◆ shorthandBytes()

static shorthandBytes (   $size)
static

Returns the size in bytes for shorthand notations (e.g.

1k -> 1024).

See also
http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
Parameters
string$sizeSize in shorthand format.
Returns
int Size in bytes.

Definition at line 32 of file Number.php.

◆ toRoman()

static toRoman (   $value)
static

Format a number as a Roman number.

Parameters
int$valueDecimal value.
Returns
string Roman representation.

Definition at line 68 of file Number.php.

◆ units()

static units (   $value,
  $units,
  $tolerance = 0 
)
static

Split a value into different units.

Parameters
float$valueNumber to split.
array$unitsUnits to split into (key = name, value = count/unit).
float$toleranceStop splitting if the remainder is smaller than this amount.
Returns
array Units (key = name, value = count), same sequence as units.

Definition at line 93 of file Number.php.


The documentation for this class was generated from the following file: