Number
class Number
Traits
Constants
| MAX_EXPONENT |
The largest scientific-notation exponent expanded by default. |
| protected DEFAULT_LOCALE |
The default locale. |
| protected DEFAULT_CURRENCY |
The default currency. |
| LOCALE_CONTEXT_KEY |
Context key for the per-request locale override. |
| CURRENCY_CONTEXT_KEY |
Context key for the per-request currency override. |
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| static protected string | $locale | The current default locale. |
|
| static protected string | $currency | The current default currency. |
Methods
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Format the given number according to the current locale.
Get the exponent of a numeric string written in scientific notation.
Determine if a numeric string exceeds the default scientific-notation exponent range.
Parse the given string according to the specified format type.
Parse a string into an integer according to the specified locale.
Parse a string into a float according to the specified locale.
Spell out the given number in the given locale.
Convert the given number to ordinal form.
Spell out the given number in the given locale in ordinal form.
Convert the given number to its percentage equivalent.
Convert the given number to its currency equivalent.
Convert the given number to its file size equivalent.
Convert the number to its human-readable equivalent.
Convert the number to its human-readable equivalent.
Convert the number to its human-readable equivalent.
Clamp the given number between the given minimum and maximum.
Split the given number into pairs of min/max values.
Remove any trailing zero digits after the decimal point of the given number.
Execute the given callback using the given locale.
Execute the given callback using the given currency.
Set the default locale.
Set the default currency.
Get the default locale.
Get the default currency.
Determine if the application has finished booting.
Ensure the "intl" PHP extension is installed.
Replace a negative number that would be formatted as zero with zero, avoiding a "-0" result.
Flush all static state.
Details
in
Macroable at line 30
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 44
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 61
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 72
static void
flushMacros()
Flush the existing macros.
Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 83
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 108
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 57
static false|string
format(float|int $number, int|null $precision = null, int|null $maxPrecision = null, string|null $locale = null)
Format the given number according to the current locale.
at line 77
static int|null
exponent(string $number)
| internal |
Get the exponent of a numeric string written in scientific notation.
at line 91
static bool
exceedsMaxExponent(string $number)
| internal |
Determine if a numeric string exceeds the default scientific-notation exponent range.
at line 101
static int|float|false
parse(string $string, int|null $type = NumberFormatter::TYPE_DOUBLE, string|null $locale = null)
Parse the given string according to the specified format type.
at line 113
static int|false
parseInt(string $string, string|null $locale = null)
Parse a string into an integer according to the specified locale.
at line 121
static float|false
parseFloat(string $string, string|null $locale = null)
Parse a string into a float according to the specified locale.
at line 129
static false|string
spell(float|int $number, string|null $locale = null, int|null $after = null, int|null $until = null)
Spell out the given number in the given locale.
at line 149
static false|string
ordinal(float|int $number, string|null $locale = null)
Convert the given number to ordinal form.
at line 161
static false|string
spellOrdinal(float|int $number, string|null $locale = null)
Spell out the given number in the given locale in ordinal form.
at line 175
static false|string
percentage(float|int $number, int $precision = 0, int|null $maxPrecision = null, string|null $locale = null)
Convert the given number to its percentage equivalent.
at line 193
static false|string
currency(float|int $number, string $in = '', string|null $locale = null, int|null $precision = null)
Convert the given number to its currency equivalent.
at line 214
static string
fileSize(float|int $bytes, int $precision = 0, int|null $maxPrecision = null)
Convert the given number to its file size equivalent.
at line 234
static false|string
abbreviate(float|int $number, int $precision = 0, int|null $maxPrecision = null)
Convert the number to its human-readable equivalent.
at line 242
static false|string
forHumans(float|int $number, int $precision = 0, int|null $maxPrecision = null, bool $abbreviate = false)
Convert the number to its human-readable equivalent.
at line 266
static protected false|string
summarize(float|int $number, int $precision = 0, int|null $maxPrecision = null, array $units = [])
Convert the number to its human-readable equivalent.
at line 315
static float|int
clamp(float|int $number, float|int $min, float|int $max)
Clamp the given number between the given minimum and maximum.
at line 325
static array
pairs(float|int $to, float|int $by, float|int $start = 0, float|int $offset = 1)
Split the given number into pairs of min/max values.
at line 355
static float|int
trim(float|int $number)
Remove any trailing zero digits after the decimal point of the given number.
at line 372
static mixed
withLocale(string $locale, callable $callback)
Execute the given callback using the given locale.
at line 397
static mixed
withCurrency(string $currency, callable $callback)
Execute the given callback using the given currency.
at line 417
static void
useLocale(string $locale)
Set the default locale.
at line 431
static void
useCurrency(string $currency)
Set the default currency.
at line 445
static string
defaultLocale()
Get the default locale.
at line 453
static string
defaultCurrency()
Get the default currency.
at line 461
static protected bool
applicationIsBooted()
Determine if the application has finished booting.
at line 471
static protected void
ensureIntlExtensionIsInstalled()
Ensure the "intl" PHP extension is installed.
at line 485
static protected float|int
withoutNegativeZero(float|int $number, callable $format)
Replace a negative number that would be formatted as zero with zero, avoiding a "-0" result.
at line 497
static void
flushState()
Flush all static state.