Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
number-string
Advanced tools
Readme
Convert a string to number disregarding other characters
import { toNumber } from "number-string";
toNumber("$1.57"); // 1.57
Parameters:
toNumber(stringOrNumber, {
decimalMark = ".",
});
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 = ".",
});
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,
});
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,
});
Rounds to the closest interval
import { toClosest } from "number-string";
toClosest(12.6, 7.1); // 14.2
Parameters:
toClosest(stringOrNumber, roundToNearestNumber);
FAQs
Functions to format number to string
The npm package number-string receives a total of 108 weekly downloads. As such, number-string popularity was classified as not popular.
We found that number-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.