adampatterson/numeral

A PHP library for formatting and manipulating numbers.

0.0.7 2016-02-22 23:18 UTC

This package is auto-updated.

Last update: 2024-11-04 08:46:25 UTC


README

PHP Composer Packagist Version Packagist Downloads

A PHP library for formatting and manipulating numbers.

This script is still under development and a PHP clone of Numeral-js by Adam Draper.

Install from Packagist

composer require adampatterson/numeral

For use in Laravel Views ( Blade files )

Open config/app.php and add Numeral to the aliases array.

'Numeral'      => Numeral\Numeral::class

{{ \Numeral::number(85193.456)->format('0.00') }}

Usage

use Numeral\Numeral;

class SomeController extends Controller
{
    public function myMethod(Numeral $numeral){
        $numeral->number('85193.456')->format()
    }
    
    // OR

    public function myOtherMethod(){
        Numeral::number('85193.456')->format()
    }
}

Numbers

var_dump(Numeral::number('85193.456')->format()); // 85193
var_dump(Numeral::number('85193.456')->format('0.00')); // 85193.46
var_dump(Numeral::number('85193.456')->format('0,0.00')); // 85,193.46
var_dump(Numeral::number('-85193.00')->format()); // -85193
var_dump(Numeral::number('-85193')->format('0.00')); // -85193.00

Percentages

var_dump(Numeral::number('-0.43')->format('0%')); // -43%
var_dump(Numeral::number('0.75')->format('0%')); // 75%

Time

var_dump(Numeral::number('25')->format('00:00:00')); // 0:00:25
var_dump(Numeral::number('238')->format('00:00:00')); // 0:03:58
var_dump(Numeral::number('63846')->format('00:00:00')); // 17:44:06

Currency

Work in progress.

var_dump(Numeral::number('85187993.00')->format('$0,0.00')); // $85,187,993.00
var_dump(Numeral::number('85187993.00')->format('$0,0')); // $85,187,993
var_dump(Numeral::number('$85187993.00')->format('$0.00')); // $85187993.00
var_dump(Numeral::number('85187993.00')->format('$0')); // $85187993

Un-format

Work in progress.

Tests

$ composer global require phpunit/phpunit
$ export PATH=~/.composer/vendor/bin:$PATH
$ which phpunit
~/.composer/vendor/bin/phpunit

composer run-script test

Local Dev

ln -s ~/Sites/personal/_packages/Numeral/ ~/Sites/personal/projectName/vendor/adampatterson/Numeral