Number
class Number
Traits
Constants
| 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.
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.
Spell out the given number in the given locale in ordinal form.
Convert the given number to 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.
Ensure the "intl" PHP extension is installed.
Flush all static state.
Details
in
Macroable at line 28
static void
macro(string $name, callable|object $macro)
Register a custom macro.
Boot-only. Macros persist in a static property for the worker lifetime and apply to every subsequent call on the macroable class.
in
Macroable at line 41
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
Boot-only. Delegates to macro() for each method; registered macros persist in a static property for the worker lifetime.
in
Macroable at line 57
static bool
hasMacro(string $name)
Check if macro is registered.
in
Macroable at line 68
static void
flushMacros()
Flush the existing macros.
Boot or tests only. Clears worker-wide macros; concurrent coroutines may resolve different methods depending on timing.
in
Macroable at line 78
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
in
Macroable at line 103
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 40
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 58
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 70
static int|false
parseInt(string $string, string|null $locale = null)
Parse a string into an integer according to the specified locale.
at line 78
static float|false
parseFloat(string $string, string|null $locale = null)
Parse a string into a float according to the specified locale.
at line 86
static 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 106
static string
spellOrdinal(float|int $number, string|null $locale = null)
Spell out the given number in the given locale in ordinal form.
at line 120
static string
ordinal(float|int $number, string|null $locale = null)
Convert the given number to ordinal form.
at line 132
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 150
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 166
static string
fileSize(float|int $bytes, int $precision = 0, int|null $maxPrecision = null)
Convert the given number to its file size equivalent.
at line 186
static bool|string
abbreviate(float|int $number, int $precision = 0, int|null $maxPrecision = null)
Convert the number to its human-readable equivalent.
at line 194
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 216
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 259
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 267
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 293
static float|int
trim(float|int $number)
Remove any trailing zero digits after the decimal point of the given number.
at line 305
static mixed
withLocale(string $locale, callable $callback)
Execute the given callback using the given locale.
at line 321
static mixed
withCurrency(string $currency, callable $callback)
Execute the given callback using the given currency.
at line 337
static void
useLocale(string $locale)
Set the default locale.
at line 345
static void
useCurrency(string $currency)
Set the default currency.
at line 353
static string
defaultLocale()
Get the default locale.
at line 361
static string
defaultCurrency()
Get the default currency.
at line 369
static protected void
ensureIntlExtensionIsInstalled()
Ensure the "intl" PHP extension is installed.
at line 381
static void
flushState()
Flush all static state.