class Number (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
static protected string $locale

The current default locale.

Methods

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

Register a custom macro.

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

Mix another object into the class.

static bool
hasMacro(string $name)

Checks 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 string|false
format(int|float $number, int|null $precision = null, int|null $maxPrecision = null, string|null $locale = null)

Format the given number according to the current locale.

static string
spell(int|float $number, string|null $locale = null, int|null $after = null, int|null $until = null)

Spell out the given number in the given locale.

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

Convert the given number to ordinal form.

static string|false
percentage(int|float $number, int $precision = 0, int|null $maxPrecision = null, string|null $locale = null)

Convert the given number to its percentage equivalent.

static string|false
currency(int|float $number, string $in = 'USD', string|null $locale = null)

Convert the given number to its currency equivalent.

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

Convert the given number to its file size equivalent.

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

Convert the number to its human-readable equivalent.

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

Convert the number to its human-readable equivalent.

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

Convert the number to its human-readable equivalent.

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

Clamp the given number between the given minimum and maximum.

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

Execute the given callback using the given locale.

static void
useLocale(string $locale)

Set the default locale.

static void
ensureIntlExtensionIsInstalled()

Ensure the "intl" PHP extension is installed.

Details

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

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

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

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

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

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static string|false format(int|float $number, int|null $precision = null, int|null $maxPrecision = null, string|null $locale = null)

Format the given number according to the current locale.

Parameters

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

Return Value

string|false

static string spell(int|float $number, string|null $locale = null, int|null $after = null, int|null $until = null)

Spell out the given number in the given locale.

Parameters

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

Return Value

string

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

Convert the given number to ordinal form.

Parameters

int|float $number
string|null $locale

Return Value

string

static string|false percentage(int|float $number, int $precision = 0, int|null $maxPrecision = null, string|null $locale = null)

Convert the given number to its percentage equivalent.

Parameters

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

Return Value

string|false

static string|false currency(int|float $number, string $in = 'USD', string|null $locale = null)

Convert the given number to its currency equivalent.

Parameters

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

Return Value

string|false

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

Convert the given number to its file size equivalent.

Parameters

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

Return Value

string

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

Convert the number to its human-readable equivalent.

Parameters

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

Return Value

bool|string

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

Convert the number to its human-readable equivalent.

Parameters

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

Return Value

bool|string

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

Convert the number to its human-readable equivalent.

Parameters

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

Return Value

string|false

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

Clamp the given number between the given minimum and maximum.

Parameters

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

Return Value

int|float

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

Execute the given callback using the given locale.

Parameters

string $locale
callable $callback

Return Value

mixed

static void useLocale(string $locale)

Set the default locale.

Parameters

string $locale

Return Value

void

static protected void ensureIntlExtensionIsInstalled()

Ensure the "intl" PHP extension is installed.

Return Value

void