Number

Introduction

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.

reduce() – Scaling Down a Number

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);

currency() – Formatting a Number as Currency

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');

percent() – Transforming a Value into a Percentage

The percent() method converts a numerical value into its percentage representation.

echo Number::percent(0.123);

spell() – Converts Numbers to Words

Transforms numeric values into their text equivalent.

echo Number::spell(12345678);

format() – Number Formatting for Readability

Formats numbers with thousand separators, decimal precision, and currency symbols.

echo Number::format(12345678.9);

clamp() – Restricting a Number Within a Range

Constrains a number to stay within the specified boundaries.

echo Number::clamp(-2, 1, 100);

toRoman() – Converting Numbers to Roman Numerals

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);

What to see next?


Built with MkDocs.