npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

currency-to-abbreviation

v2.0.1

Published

Convert numbers to abbreviated currency values. Example: 1000000 -> $1M

Downloads

5,268

Readme

currency-to-abbreviation

currency-to-abbreviation is a simple package for converting numbers to currency abbreviations. Example: 1000000 -> $1M

npm i currency-to-abbreviation

Examples

import { CurrencyToAbbreviation } from "currency-to-abbreviation"
//Basic Example
CurrencyToAbbreviation({ inputNumber: 115131874 }) // Output: $115.1M

// <1
CurrencyToAbbreviation({ inputNumber: 0.8987456 }) // Output: $0.90
CurrencyToAbbreviation({ inputNumber: 0.8987456, inputLocale:'de-DE', inputCurrencyCode:'EUR', decimalPlacesToRound:4 }) // Output: €0,8987

// >=1 && <100
CurrencyToAbbreviation({ inputNumber: 95.53 }) // Output: $95.53
CurrencyToAbbreviation({ inputNumber: 95.59, inputCurrencyCode:'JPY', dcimalPlacesToRound: 0 }) //Output: ¥96

// >=100 && <1,000
CurrencyToAbbreviation({ inputNumber: 255.59 }) // Output: $256
CurrencyToAbbreviation({ inputNumber: 255.59, inputLocale:'es-ES', inputCurrencyCode:'EUR', decimalPlacesToRound:0 }) //Output: €255,59

// >=1,000 && <1,000,000 (Thousands)
CurrencyToAbbreviation({ inputNumber: 3535.564 }) //Output: $3.5K
CurrencyToAbbreviation({ inputNumber: 3535.564, inputCurrencyCode:'CAD', decimalPlacesToRound: 3, lowerCaseAbbreviation: true }) //Output: CA$3.536k

// >=1,000,000 && <1,000,000,000 (Millions)
CurrencyToAbbreviation({ inputNumber: 98432654.56 }) //Output: $98.4M
CurrencyToAbbreviation({inputNumber: 3537565.564, inputLocale: "es-ES", inputCurrencyCode: "EUR", decimalPlacesToRound: 2, lowerCaseAbbreviation: true}) //Output: €3,54m

// >=1,000,000,000 && <1,000,000,000,000 (Billions)
CurrencyToAbbreviation({ inputNumber: 3153756565 }) //Output: $3.2B
CurrencyToAbbreviation({inputNumber: 3153756565, inputLocale: "en-US", inputCurrencyCode: "EUR", decimalPlacesToRound: 3, lowerCaseAbbreviation: true}) //Output: €3.154b

// >=1,000,000,000,000 (Tillions)
CurrencyToAbbreviation({ inputNumber: 482658526862325 }) //Output: $482.7T
CurrencyToAbbreviation({inputNumber: 482658526862325, inputLocale: "en-US", inputCurrencyCode: "JPY", decimalPlacesToRound: 0, lowerCaseAbbreviation: true}) //Output: ¥483t

CurrencyToAbbreviation Parameters

|Parameter | Required | Description/Defaults | :--- | :--- | :--- | |inputNumber | Yes | Must provide a valid number (typeof === "number") |inputLocale | No | Optionally provide a valid local ("en-US", "de-DE", etc.). If a local is not provided it will attempt to find the user's locale using Intl?.DateTimeFormat()?.resolvedOptions()?.locale. Lastly, it defaults to "en-US" |inputCurrencyCode | No | Optionally provide a valid currency code ("USD", "EUR", "CAD", etc). Defaults to "USD" if a value is not provided or if the value is invalid. |decimalPlacesToRound | No | Optionally provide the number of decimal places to round to (typeof === "number"). The default rounding varies by the inputNumber value. By default, inputNumber values < 1 round to 2 decimals, inputNumber values >= 1 && <100 round to 2 decimals, inputNumber values >= 100 && <1000 round to 0 decimals, and inputNumber values >= 1000 round to 1 decimal. |lowerCaseAbbreviation | No | Optionally provide a boolean to determine whether the value abbreviation will be uppercase or lowercase. By default this value is false, meaning the value abbreviation will be uppercase (ex: "€12,6M"). If true is passed, the value abbreviation will be lowercase (ex: "$18.9t").

Opinionated Choices

This package was originally created for use by CurrencyRush.com and it remains opinionated for our use case.

In the packages current form, the default handling of missing parameters meet our needs, but give little flexibility if your needs differ. We're unlikely to be interested in making changes to our opinionated choices, but feel free to fork the project or use the code as a jumping off point for your own needs.

However we are happy to be notified of any problems or errors experiences.