Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
currency-to-abbreviation
Advanced tools
Convert numbers to abbreviated currency values. Example: 1000000 -> $1M
currency-to-abbreviation is a simple package for converting numbers to currency abbreviations. Example: 1000000 -> $1M
npm i currency-to-abbreviation
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
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" ). |
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.
FAQs
Convert numbers to abbreviated currency values. Example: 1000000 -> $1M
The npm package currency-to-abbreviation receives a total of 0 weekly downloads. As such, currency-to-abbreviation popularity was classified as not popular.
We found that currency-to-abbreviation 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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.