The Number component in Solital Framework provides a set of powerful methods for handling numeric operations with precision and flexibility. Whether you're formatting, clamping, converting, or reducing numbers, this component ensures a streamlined approach to numerical manipulation.
The reduce()
method simplifies large numbers by converting them into more readable values using thousands (K), millions (M), and billions (B).
use Solital\Core\Resource\Number;
echo Number::reduce(1.2335566);
The currency()
method formats a numerical value into a specific currency format, supporting different locales and currency symbols (USD, EUR, BRL, and others).
echo Number::currency(12345678.90, 'BRL');
The percent()
method converts a numerical value into its percentage representation.
echo Number::percent(0.123);
Transforms numeric values into their text equivalent.
echo Number::spell(12345678);
Formats numbers with thousand separators, decimal precision, and currency symbols.
echo Number::format(12345678.9);
Constrains a number to stay within the specified boundaries.
echo Number::clamp(-2, 1, 100);
The toRoman()
method transforms an integer into its Roman numeral equivalent. This is useful for formatting dates, numbering lists, or historical references.
echo Number::toRoman(10);