Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

convert-string-to-number

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convert-string-to-number

Convert a string to its numerical value (float or integer)

  • 1.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2K
increased by11.9%
Maintainers
1
Weekly downloads
 
Created
Source

convert-string-to-number

npm Travis branch Codecov branch

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 = convertStringToNumber(value);
Parameters
  • value: a string

Usage

An example how to use it.

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

Keywords

FAQs

Package last updated on 07 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc