Coder Social home page Coder Social logo

readable-numbers's Introduction

Readable Numbers

EgoistDeveloper Readable Numbers

Stable Version Unstable Version Total Downloads License

Human readable numbers for Laravel. In some cases, you may need to format numbers in a way that is easier to read. Especially when you are dealing with numbers that are very large, for example we want to show page views and we have 100000000 views. So we can show it in the 100M format.

Installation

composer require laravel-ready/readable-numbers

Thresholds

Threshold Suffix Result
900 900
900.000 k 0.9 K
900.000.000 m 0.9 M
900.000.000.000 b 9 T
90.000.000.000.000 t 900 T

Usages

make method takes 3 aguments: make(float $value, int $decimals = 1, $lang = null)

Service Example

use LaravelReady\ReadableNumbers\Services\ReadableNumbers;

...

$readableNumber = ReadableNumbers::make(123456789); // 123.5 M
$readableNumber = ReadableNumbers::make(-123456789); // -123.5 M

// with more decimals
$readableNumber = ReadableNumbers::make(123456789, 2); // 123.46 M

// with target language (default is english)
$readableNumber = ReadableNumbers::make(123456789, 2, 'tr'); // 123.46 Mn
$readableNumber = ReadableNumbers::make(123456789, 3, 'ja'); // 123.457 ๅ„„
$readableNumber = ReadableNumbers::make(123456789, 4, 'de'); // 123.4568 Mio.

Directive Example

There is only one directive: @readableNumber(), again takes three arguments: @readableNumber(float $value, int $decimals = 1, $lang = null). If you use a multi-language system, you should remember to directives are cached. So, you should pass decimal count and language.

...

<span>
    @readableNumber(123456789, 1, app()->getLocale())
</span>

...

<span class="view-counter">
    <i class="icon icon-eye"></i>

    Viewed @readableNumber($blogPost->views, 1, app()->getLocale()) times
</span>

Languages

Supported languages are listed here and reference are used in unicode.org. If you want to add your own language and send PR.

Don't forget to these shortings are depends on a mathematical view.

readable-numbers's People

Contributors

ishado avatar relliv avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ishado coolsam726

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.