Socket
Socket
Sign inDemoInstall

number-string

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    number-string

Functions to format number to string


Version published
Weekly downloads
130
decreased by-24.86%
Maintainers
1
Install size
12.8 kB
Created
Weekly downloads
 

Readme

Source

Actions Status npm downloads npm License GitHub issues GitHub stars

Usage

.toNumber

Convert a string to number disregarding other characters

import { toNumber } from "number-string";

toNumber("$1.57"); // 1.57

Parameters:

toNumber(stringOrNumber, {
  decimalMark = ".",
});

.toNumberString

Convert a string to string of the numbers disregarding other characters

import { toNumberString } from "number-string";

toNumberString("$1.57"); // "1.57"

Parameters:

toNumberString(stringOrNumber, {
  decimalMark = ".",
});

.toClean

Like toFixed but removes trailing 0's

import { toClean } from "number-string";

toClean(1.5009, {maxPrecision: 2}); // "1.5"

Parameters:

toClean(stringOrNumber, {
	decimalMark = ".",
	thousandSeparator = ",",
	maxPrecision = 10, // maximum precision possible is 10 to prevent floating point errors
	minPrecision = 0,
});

.toMoney

Converts number to currency

import { toMoney } from "number-string";

toMoney(-1234.5); // "($1,234.50)"

Parameters:

toMoney(stringOrNumber, {
	decimalMark = ".",
	thousandSeparator = ",",
	maxPrecision = 2, // maximum precision possible is 10 to prevent floating point errors
	minPrecision = 2,
	symbol = "$",
	symbolBehind = false,
	useParens = true,
});

.toClosest

Rounds to the closest interval

import { toClosest } from "number-string";

toClosest(12.6, 7.1); // 14.2

Parameters:

toClosest(stringOrNumber, roundToNearestNumber);

Keywords

FAQs

Last updated on 02 Nov 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc