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

static void
macro(string $name, callable|object $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Check if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Dynamically handle calls to the class.

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.

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.

static int|false
parseInt(string $string, string|null $locale = null)

Parse a string into an integer according to the specified locale.

static float|false
parseFloat(string $string, string|null $locale = null)

Parse a string into a float according to the specified locale.

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.

static string
spellOrdinal(float|int $number, string|null $locale = null)

Spell out the given number in the given locale in ordinal form.

static string
ordinal(float|int $number, string|null $locale = null)

Convert the given number to ordinal form.

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.

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.

static string
fileSize(float|int $bytes, int $precision = 0, int|null $maxPrecision = null)

Convert the given number to its file size equivalent.

static bool|string
abbreviate(float|int $number, int $precision = 0, int|null $maxPrecision = null)

Convert the number to its human-readable equivalent.

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.

static false|string
summarize(float|int $number, int $precision = 0, int|null $maxPrecision = null, array $units = [])

Convert the number to its human-readable equivalent.

static float|int
clamp(float|int $number, float|int $min, float|int $max)

Clamp the given number between the given minimum and maximum.

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.

static float|int
trim(float|int $number)

Remove any trailing zero digits after the decimal point of the given number.

static mixed
withLocale(string $locale, callable $callback)

Execute the given callback using the given locale.

static mixed
withCurrency(string $currency, callable $callback)

Execute the given callback using the given currency.

static void
useLocale(string $locale)

Set the default locale.

static void
useCurrency(string $currency)

Set the default currency.

static string
defaultLocale()

Get the default locale.

static string
defaultCurrency()

Get the default currency.

static void
ensureIntlExtensionIsInstalled()

Ensure the "intl" PHP extension is installed.

static void
flushState()

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.

Parameters

string $name
callable|object $macro

Return Value

void

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.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

in Macroable at line 57
static bool hasMacro(string $name)

Check if macro is registered.

Parameters

string $name

Return Value

bool

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.

Return Value

void

in Macroable at line 78
static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

in Macroable at line 103
mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

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.

Parameters

float|int $number
int|null $precision
int|null $maxPrecision
string|null $locale

Return Value

false|string

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.

Parameters

string $string
int|null $type
string|null $locale

Return Value

int|float|false

at line 70
static int|false parseInt(string $string, string|null $locale = null)

Parse a string into an integer according to the specified locale.

Parameters

string $string
string|null $locale

Return Value

int|false

at line 78
static float|false parseFloat(string $string, string|null $locale = null)

Parse a string into a float according to the specified locale.

Parameters

string $string
string|null $locale

Return Value

float|false

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.

Parameters

float|int $number
string|null $locale
int|null $after
int|null $until

Return Value

string

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.

Parameters

float|int $number
string|null $locale

Return Value

string

at line 120
static string ordinal(float|int $number, string|null $locale = null)

Convert the given number to ordinal form.

Parameters

float|int $number
string|null $locale

Return Value

string

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.

Parameters

float|int $number
int $precision
int|null $maxPrecision
string|null $locale

Return Value

false|string

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.

Parameters

float|int $number
string $in
string|null $locale
int|null $precision

Return Value

false|string

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.

Parameters

float|int $bytes
int $precision
int|null $maxPrecision

Return Value

string

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.

Parameters

float|int $number
int $precision
int|null $maxPrecision

Return Value

bool|string

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.

Parameters

float|int $number
int $precision
int|null $maxPrecision
bool $abbreviate

Return Value

false|string

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.

Parameters

float|int $number
int $precision
int|null $maxPrecision
array $units

Return Value

false|string

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.

Parameters

float|int $number
float|int $min
float|int $max

Return Value

float|int

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.

Parameters

float|int $to
float|int $by
float|int $start
float|int $offset

Return Value

array

at line 293
static float|int trim(float|int $number)

Remove any trailing zero digits after the decimal point of the given number.

Parameters

float|int $number

Return Value

float|int

at line 305
static mixed withLocale(string $locale, callable $callback)

Execute the given callback using the given locale.

Parameters

string $locale
callable $callback

Return Value

mixed

at line 321
static mixed withCurrency(string $currency, callable $callback)

Execute the given callback using the given currency.

Parameters

string $currency
callable $callback

Return Value

mixed

at line 337
static void useLocale(string $locale)

Set the default locale.

Parameters

string $locale

Return Value

void

at line 345
static void useCurrency(string $currency)

Set the default currency.

Parameters

string $currency

Return Value

void

at line 353
static string defaultLocale()

Get the default locale.

Return Value

string

at line 361
static string defaultCurrency()

Get the default currency.

Return Value

string

at line 369
static protected void ensureIntlExtensionIsInstalled()

Ensure the "intl" PHP extension is installed.

Return Value

void

at line 381
static void flushState()

Flush all static state.

Return Value

void