GithubHelp home page GithubHelp logo

friendsofphp / number Goto Github PK

View Code? Open in Web Editor NEW
9.0 5.0 2.0 55 KB

A PHP Number package focusing on developer experience when dealing with numbers of all kinds and locales

Home Page: https://friendsofphp.github.io/number

License: MIT License

PHP 100.00%

number's Introduction

PHP Number Utility

This library provides a set of utility functions for working with numbers in PHP, including formatting as currency, percentages, ordinals, and more.

Installation

composer require friendsofphp/number

Usage

Basic usage

use FriendsOfPhp\Number\Number;

// Format a number
echo Number::format(1234567.89); // 1,234,567.89

// Spell out a number
echo Number::spell(1234567.89); // one thousand two hundred thirty-four

// Get the ordinal form of a number
echo Number::ordinal(1234567.89); // 42nd

// Format a number as a percentage
echo Number::percentage(1234567.89); // 1%

// Format a number as currency
echo Number::currency(1234567.89, 'EUR'); // €1,234.56

// Format file size
echo Number::fileSize(1234567.89); // 1 KB

// Get a human-readable representation of a number
echo Number::format(1234567.89); // 1 million

// Get the abbreviated form of a number
echo Number::format(1234567.89); // 1M

Advanced usage

use FriendsOfPhp\Number\Number;

// Set a custom locale
Number::useLocale('fr');

// Use the custom locale for formatting
$formattedNumber = Number::format(1234.56);

// Change the precision when formatting
$preciseNumber = Number::format(1234.56789, 2);

// Use a custom locale for currency formatting
$currencyFormatted = Number::currency(1234.56, 'GBP', 'fr');

Information

Documentation

You can visit the documentation at friendsofphp.github.io/number

License

This package is open-sourced software licensed under the MIT License.

Attributions

The Number utility is ported from Laravel, licensed under the MIT Licence.

number's People

Contributors

caendesilva avatar damienalexandre avatar pierrejoye avatar

Stargazers

Rune Bonsu avatar Christos Athanasiadis avatar Thomas Bruninx avatar Christian Phyo avatar  avatar Cyril Fehintoluwa avatar Tobias Sette avatar Cristian Busoi avatar  avatar

Watchers

 avatar Grégoire Pineau avatar  avatar  avatar  avatar

number's Issues

Initial Release Discussion

Abstract

Hey everyone! Quick introduction here. I'm Caen, creator of the Number PR of Laravel. In this repo I'm porting that utility so it can be used in all PHP projects. This is my first Friends Of PHP Package, so I'm starting this discussion to ensure that everything matches the style and structure of your other packages.

Note: This issue continues the discussion from #1

Checklist

These are the things we need before releasing v1.0

  • #1
  • #3 (Would love to get feedback on this, especially on where to host it)

Context: Documentation site

How do you want to handle documentation? My go-to for simple packages is to use GitHub Pages to create a static site from the README (or Markdown docs in the repo) using HydePHP. (For example hydephp.github.io/action and git.desilva.se/Speacher which both just need a short GitHub Actions workflow)

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.