PHP Classes

Laravel Numeral: Perform operations and format number values

Recommend this page to a friend!
  Info   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-04-01 (5 days ago) RSS 2.0 feedNot enough user ratingsTotal: 11 This week: 11All time: 11,270 This week: 7Up
Version License PHP version Categories
laravel-numeral 1.0MIT/X Consortium ...8.2Algorithms, Libraries, Math, PHP 8
Description 

Author

This package can perform operations and format number values.

It provides two classes that provide several functions to perform several operations on numbers that can be taken from strings.

One class is a base class that implements base number operations. The other is a numeral class that provides the same functions, assuming specific default values of the class function parameters.

Currently, the base class provides functions to:

- Check if the value is numeric, odd, even, integer, float, positive, negative, or zero

- Change the sign of the number between positive and negative

- Format the number as a string

- Spell the number with words

- Convert the number to the 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.

- Counts the length of a numeral.

- Returns a random number using the Randomizer class from PHP.

- Returns a random number between the given min and max values.

- Get the greatest common divisor of two numbers.

- Get the least common multiple of two numbers.

- Get the factorial of a number.

Picture of Alun
  Performance   Level  
Name: Alun <contact>
Classes: 2 packages by
Country: Spain Spain
Innovation award
Innovation award
Nominee: 1x

Details

laravel-numeral

What is it?

This package inlines the Number helper with the Str helper. It does so by adding some functionality as well as introducing a number of tools:

Garanaw\LaravelNumeral\Support\Numeral

This class is the one that should align with the existing Stringable. This wrapper allows chaining operations on numbers. Most of the native operations from PHP have been added, along with other helper functions. Some basic equations like fractals have been also added to this.

It uses the same traits than its sibling Stringable, however it's lacking some interfaces (JsonSerializable, ArrayAccess) as those don't apply to this scalar. PHP's \Stringable (not to be confused with Illuminate\Support\Stringable) is implemented in order to cast the value to a string and allow visual representation in Blade (this is done with the existing Number's method format().

The decision of using this name instead of Numerable to fully align it with Stringable is due to the definition provided by Oxford's dictionary for the word "numeral": able to be counted

The class supports integers and floats.

Garanaw\LaravelNumeral\Support\Number

New functionality has been added to this helper. Not everything that appears in Numeral has been doubled here, because simple operations such as additions would imply more cumbersomeness when used here rather than just doing 1 + 1.

However, a new random() method has been introduced here as a wrapper for PHP's Random\Randomizer(). This functionality doesn't exist in the stateful class

num()

To mimic the str() helper, a new num() helper has been introduced with similar functionality. This helper will return a Numeral object with the value passed as a parameter.

Garanaw\LaravelNumeral\Casts\AsNumeral

A new cast has also been added to the Eloquent's Casts folder. This will cast integers and floats to Numerals and back.


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file, 2 directories)
Files folder imagetests (2 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageCasts (1 file)
Files folder imageSupport (2 files)
  Plain text file helpers.php Class Class source

  Files folder image Files  /  src  /  Casts  
File Role Description
  Plain text file AsNumeral.php Class Class source

  Files folder image Files  /  src  /  Support  
File Role Description
  Plain text file Number.php Class Class source
  Plain text file Numeral.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageUnit (3 files)
  Plain text file Pest.php Class Class source
  Plain text file TestCase.php Class Class source

  Files folder image Files  /  tests  /  Unit  
File Role Description
  Plain text file AsNumeralTest.php Class Class source
  Plain text file NumberTest.php Class Class source
  Plain text file NumeralTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:11
This week:11
All time:11,270
This week:7Up