Number
class Number
Traits
Constants
| 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.
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.
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 52
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 70
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 82
static int|false
parseInt(string $string, string|null $locale = null)
Parse a string into an integer according to the specified locale.
at line 90
static float|false
parseFloat(string $string, string|null $locale = null)
Parse a string into a float according to the specified locale.
at line 98
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 118
static false|string
ordinal(float|int $number, string|null $locale = null)
Convert the given number to ordinal form.
at line 130
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 144
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 162
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 178
static string
fileSize(float|int $bytes, int $precision = 0, int|null $maxPrecision = null)
Convert the given number to its file size equivalent.
at line 198
static false|string
abbreviate(float|int $number, int $precision = 0, int|null $maxPrecision = null)
Convert the number to its human-readable equivalent.
at line 206
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 230
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 279
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 289
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 315
static float|int
trim(float|int $number)
Remove any trailing zero digits after the decimal point of the given number.
at line 332
static mixed
withLocale(string $locale, callable $callback)
Execute the given callback using the given locale.
at line 357
static mixed
withCurrency(string $currency, callable $callback)
Execute the given callback using the given currency.
at line 377
static void
useLocale(string $locale)
Set the default locale.
at line 391
static void
useCurrency(string $currency)
Set the default currency.
at line 405
static string
defaultLocale()
Get the default locale.
at line 413
static string
defaultCurrency()
Get the default currency.
at line 421
static protected bool
applicationIsBooted()
Determine if the application has finished booting.
at line 431
static protected void
ensureIntlExtensionIsInstalled()
Ensure the "intl" PHP extension is installed.
at line 443
static void
flushState()
Flush all static state.