convert-string-to-number
Convert a string to its numerical value (float or integer)
Table of Contents
Why?
I needed a simple way to parse string numbers to its matching numerical value, for parsing csv formatted files.
Installation
$ npm i convert-string-to-number -S
or
$ yarn add convert-string-to-number
Functions
Take a look into the usage section for a detailed example.
convertStringToNumber
Note: you can also use the default export.
This function converts a string to its numerical value (float, int, or NaN).
Syntax
Returns a number or NaN.
const number = ;
Parameters
- value: a string
Usage
An example how to use it.
const convertStringToNumber = ; // named exportconst converter = ; // default export const int = ; // => 2const float = ; // => 2.2const notANumber = ; // => NaN
License
MIT © Lukas Aichbauer