https://github.com/aichbauer/node-convert-string-to-number
Convert a string to its numerical value (float or integer)
https://github.com/aichbauer/node-convert-string-to-number
converter float integer nodejs number string string-parser
Last synced: 9 months ago
JSON representation
Convert a string to its numerical value (float or integer)
- Host: GitHub
- URL: https://github.com/aichbauer/node-convert-string-to-number
- Owner: aichbauer
- License: mit
- Created: 2018-04-05T08:36:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-03-07T03:20:42.000Z (almost 4 years ago)
- Last Synced: 2025-03-26T06:43:17.910Z (9 months ago)
- Topics: converter, float, integer, nodejs, number, string, string-parser
- Language: JavaScript
- Size: 68.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# convert-string-to-number
[](https://www.npmjs.com/package/convert-string-to-number)
[](https://travis-ci.org/aichbauer/node-convert-string-to-number)
[](https://codecov.io/gh/aichbauer/node-convert-string-to-number)
> Convert a string to its numerical value (float or integer)
## Table of Contents
* [Why?](#why)
* [Installation](#installation)
* [Functions](#functions)
* [Usage](#usage)
* [License](#license)
## Why?
I needed a simple way to parse string numbers to its matching numerical value, for parsing csv formatted files.
## Installation
```sh
$ npm i convert-string-to-number -S
```
or
```sh
$ yarn add convert-string-to-number
```
## Functions
Take a look into the [usage section](#usage) 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.
```js
const number = convertStringToNumber(value);
```
##### Parameters
* **value**: a string
## Usage
An example how to use it.
```js
const { convertStringToNumber } = require('convert-string-to-number'); // named export
const converter = require('convert-string-to-number'); // default export
const int = convertStringToNumber('2'); // => 2
const float = converter('2.2'); // => 2.2
const notANumber = converter('franz'); // => NaN
```
## License
MIT © Lukas Aichbauer