asg-ktb-fe-02

1.0.10 • Public • Published

asg-ktb-fe-02

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 asg-ktb-fe-02 -S

or

$ yarn add asg-ktb-fe-02

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('asg-ktb-fe-02'); // named export
const converter = require('asg-ktb-fe-02'); // default export

const int = convertStringToNumber('2'); // => 2
const float = converter('2.2'); // => 2.2
const notANumber = converter('franz'); // => NaN

License

MIT © AsG

Package Sidebar

Install

npm i asg-ktb-fe-02

Weekly Downloads

1

Version

1.0.10

License

MIT

Unpacked Size

46.2 kB

Total Files

25

Last publish

Collaborators

  • asgundogdu4e