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.
num-format
Advanced tools
Readme
Number pretty printer for currency, percents, and adding thousands separators.
number
: Number - Value to convertroundToInteger
: Boolean - Defaults to true
(Optional)locale
: String - Defaults to 'en-US'
(Optional)currency
: String - Defaults to 'USD'
(Optional) // Pretty Print: Currency (w/ Cents - Trailing 0s)
>> FormatCurrency(123456, false); // '$123,456.00'
// Pretty Print: Currency (w/ Cents)
>> FormatCurrency(123456.78, false); // '$123,456.78'
// Pretty Print: Currency (Rounded)
>> FormatCurrency(9876.54); // '$9,877'
// Pretty Print: Currency (Locale Override - United Kingdom - Integer)
>> FormatCurrency(123456.78, true, 'en-GB', 'GBP'); // '£123,457'
number
: Number - Value to convertprecision
: Number - Defaults to 2
(Optional)locale
: String - Defaults to 'en-US'
(Optional) // Pretty Print: Number (2 places)'
>> FormatNumber(1000); // '1,000'
// Pretty Print: Number (1 place)'
>> FormatNumber(1234567.89, 1); // '1,234,567.9'
// Pretty Print: Number (0 places - Round)'
>> FormatNumber(22333.44, 0); // '22,333'
number
: Number - Value to convertprecision
: Number - Defaults to 2
(Optional)locale
: String - Defaults to 'en-US' (Optional) // Pretty Print: Percentage (2 places)'
>> FormatPercent(0.8522); // '85.22%'
// Pretty Print: Percentage (Trailing 0)'
>> FormatPercent(0.135); // '13.50%'
// Pretty Print: Percentage (1 place)'
>> FormatPercent(0.7337, 1); // '73.4%'
// Pretty Print: Percentage (0 places - Round Up)'
>> FormatPercent(0.5567, 0); // '56%'
// Pretty Print: Percentage (0 places - Round Down)
>> FormatPercent(0.3312, 0); // '33%'
In the current version of num-format it should be assumed that only en-US
formatting is supported as Node 8.x has limited locale support.
FAQs
Pretty Printer for Currency, Percentages, Numbers
The npm package num-format receives a total of 109 weekly downloads. As such, num-format popularity was classified as not popular.
We found that num-format 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.