Giter VIP home page Giter VIP logo

numberstrings's Introduction

NumberStrings.js

A simple Javascript class that formats numeric values into a more readable format.

By default it will format up to a septillion (1,000,000,000,000,000,000,000,000), however you can pass your own list of units to the constructor if you would like to overwrite/extend the default list of units (more on that below).

If you have any ideas;

  • for new features
  • to improve performance

please let me know by creating an issue/pull request!

Basic Usage:

var ns = new NumberStrings();
console.log('1,000 = ' + ns.format(1000)); // outputs: "1,000 = 1 thousand"
console.log('50,000,000 = ' + ns.format(50000000)); // outputs: "50,000,000 = 50 million"
console.log('999,999,999 = ' + ns.format(999999999)); // outputs: "999,999,999 = 999.999999 million"

Advanced Usage:

The below methods are useful if you want to further format the decimal or unit name that is returned before they are concatinated into a string (default behavior of ns.format(integer)).

getName(integer):

var ns = new NumberStrings();
ns.getName(1000); // Returns the string "thousand"

getDecimal(integer):

var ns = new NumberStrings();
ns.getDecimal(1000); // Returns the decimal that goes in front of the unit name, in this case: 1

Overwritting/extending the list of units:

To overwrite/extend the default list of units, you can pass the below units option to the NumberStrings() constructor. The value is the lowest number that can possibly be counted as the specified unit name.

var ns = new NumberStrings({
        units: [
            {
                name: 'hundred',
                value: 100
            },
            {
                name: 'thousand',
                value: 1000
            },
            {
                name: 'million',
                value: 1000000
            }
            ...
        ]
    });

numberstrings's People

Contributors

jamie452 avatar

Watchers

 avatar  avatar

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.