Helpers for numbers of all sorts.
More...
|
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...
|
|
Helpers for numbers of all sorts.
Definition at line 8 of file Number.php.
◆ add()
static add |
( |
|
$value, |
|
|
|
$add = 1 , |
|
|
|
$base = null , |
|
|
|
$upper = null |
|
) |
| |
|
static |
Add a value to a non-decimal number.
- Parameters
-
string | $value | Base value in base $base. |
int | $add | Decimal value to add to $value. |
int | $base | The base the $value is in (defaults to 10). |
bool | $upper | Convert 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 |
◆ evaluate()
Evaluate a mathamatical expression.
- Parameters
-
string | $expr | Mathamatical expression. |
- Returns
- float Answer (throws Exception on error).
Definition at line 130 of file Number.php.
◆ fahrenheitToCelsius()
static fahrenheitToCelsius |
( |
|
$value | ) |
|
|
static |
◆ formatBytes()
static formatBytes |
( |
|
$size, |
|
|
|
$decimals = 1 , |
|
|
|
$dec_point = '.' , |
|
|
|
$thousands_sep = ',' , |
|
|
|
$unit_sep = ' ' |
|
) |
| |
|
static |
Formats a size in bytes to its shorthand format.
- Parameters
-
int | $size | Size in bytes. |
int | $decimals | Number of decimals. |
string | $dec_point | Separator for the decimal point. |
string | $thousands_sep | Thousands separator. |
string | $unit_sep | Separator 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 | $tolerance | Tolerance for result. |
- Returns
- array Array with numerator and denominator.
Definition at line 110 of file Number.php.
◆ shorthandBytes()
static shorthandBytes |
( |
|
$size | ) |
|
|
static |
◆ toRoman()
Format a number as a Roman number.
- Parameters
-
- 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 | $value | Number to split. |
array | $units | Units to split into (key = name, value = count/unit). |
float | $tolerance | Stop 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:
- /var/www/fred.local/vendor/rsi/helpers/src/Rsi/Number.php