Narcoleptic's Patch Mangler

    number-es5

    1.0.3 • Public • Published

    number-es5

    NPM version Build Status Clean Code Dependency Status devDependency Status License

    Browser support

    Desktop: Chrome, Safari, Firefox, Opera, IE9+

    Installation

        npm install number-es5
     
        or 
     
        jspm install npm:number-es5

    Usage

     
        var Numbers = require('number-es5');
     
        
        /**
        * precision() method is very useful.
        * It can handle the IEEE weirdness.
        */
        Nums.precision(0.01);                   // 2
        Nums.precision(4 / 5);                  // 1
        Nums.precision(9);                      // 0
        Nums.precision(10);                     // -1
        Nums.precision(1000);                   // -3
        
        /**
        * Now some more difficult.
        */
        
        // 74.44999999999999 -> 74.45 -> 2 decimals
        Nums.precision(74.35 + 0.1);                                // 2
        
        // 74.36000000000001 -> 74.36 -> 2 decimals
        Nums.precision(74.36000000000001);                          // 2
     
        // 0.30000000000000004 -> 0.3 -> 1 decimal
        Nums.precision(0.1 + 0.2);                                  // 1
        
        // 153.26999999999998 -> 153.27 -> 2 decimals
        Nums.precision(153.26 + .01);                               // 2
        
        // (1 / 3) -> 0.333333333333333 -> 14 decimals
        Nums.precision(1 / 3);                                      // 14
        
        // 22.628800000000002 -> 22.6288 -> 4 decimals
        Nums.precision(parseFloat("22.628800000000002"));           // 4
        
        // 23.760240000000003 -> 23.76024 -> 5 decimals
        Nums.precision(parseFloat("23.760240000000003"));           // 5
        
        // 998.29499999999905 -> 998.295 -> 3 decimals
        Nums.precision(parseFloat("998.29499999999905"));           // 3
        
        // 594.03500000000042 -> 594.035 -> 3 decimals
        Nums.precision(parseFloat("594.03500000000042"));           // 3
     
     
        /**
        * getFormatter() 
        */
        var num = 5.125;
        Nums.getFormatter("0.00")  (num);           // "5.13"
        Nums.getFormatter("0.0000")(num);           // "5.1250"
        Nums.getFormatter("0'1/8") (num);           // "5'1"
        
        num = 0.2467;
        Nums.getFormatter("0%")    (num);           // "25%"
        Nums.getFormatter("0.00%") (num);           // "24.67%"
        Nums.getFormatter("+0.00%")(num);           // "+24.67%"
     
        Nums.getFormatter("0'1/8") (-12.5);         // "-12'4"
     
     

    Public properties and methods :

     
            /**
             * Returns whether argument is a finite number.
             * @return {Boolean} 
             */
            isNumber: function (num)

    Tests

        npm test          

    Todo

    • Add complete document 🎈

    Install

    npm i number-es5

    DownloadsWeekly Downloads

    11

    Version

    1.0.3

    License

    MIT

    Last publish

    Collaborators

    • wenwu