one-separator-decimal

0.1.4 • Public • Published

one-separator-decimal

travis-ci.org

NPM

Converts input value to a floating-point number with separator decimal passed as paramater, locale is irrelevant. Only the last non-numeric character is considered for the conversion.

Install

npm install one-separator-decimal

Usage

    import convert from 'one-separator-decimal'
 
    ...
 
    /**
    * @license MIT License
    * @param {String} input 
    * @param {String} [separator='.'] The separator is optional, default value is a dot.
    *
    */
    let result = convert('123,456')
    //result = 123.456

Validations

NaN

√ should return NaN when the input value is `test`

mixed dots and commas

√ should return 1000 when the input value is `1,000.00`
√ should return 1000 when the input value is `1.000,00`

dots

√ should return 10 when the input value is `10.00`
√ should return 0.1 when the input value is `.1000`
√ should return 1000 when the input value is `1000.00`
√ should return 1000 when the input value is `1.000.00`
√ should return 1000 when the input value is `1.000.000`
√ should return 1000000 when the input value is `1.000.000.00`

commas

√ should return 10 when the input value is `10,00`
√ should return 0.1 when the input value is `,1000`
√ should return 1000 when the input value is `1000,00`
√ should return 1000 when the input value is `1,000,00`
√ should return 1000 when the input value is `1,000,000`
√ should return 1000000 when the input value is `1,000,000,00`

more than two decimals

√ should return 123.45678 when the input value is `123,45678`
√ should return 123.45678 when the input value is `123.45678`

License

MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i one-separator-decimal

Weekly Downloads

1

Version

0.1.4

License

MIT

Unpacked Size

11.5 kB

Total Files

8

Last publish

Collaborators

  • tiago-marques