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.
exchange-rounding
Advanced tools
Readme
ExchNumberFormat
)ExchNumberFormat
is a comprehensive and customizable number formatting utility, designed specifically for financial and cryptocurrency applications. It extends the standard Intl.NumberFormat
functionality with support for custom currencies, including cryptocurrencies, and provides additional formatting options.
useCustomCurrency
and customCurrency
options.Install the package using npm:
npm i exchange-rounding
Or using yarn:
yarn add exchange-rounding
import ExchNumberFormat from 'exchange-rounding';
// Example: Formatting a number with Bitcoin currency
const bitcoinFormatter = new ExchNumberFormat('en-US', {
style: 'currency',
currency: 'BTC',
roundingMode: 'halfFloor',
currencyDisplay: 'symbol'
});
const formattedBTC = bitcoinFormatter.format(1234.567);
console.log(formattedBTC); // Output: '₿1,234.567'
// Example: Formatting with custom options
const customFormatter = new ExchNumberFormat('en-US', {
style: 'decimal',
minimumFractionDigits: 2,
maximumFractionDigits: 5
});
const formattedNumber = customFormatter.format(1234.56789);
console.log(formattedNumber); // Output: '1,234.56789'
const customCurrencyData = {
'XCB': {
symbol: '₡',
narrowSymbol: '₡',
code: 'XCB',
name: 'CoreCoin',
defaultDecimals: 2
}
};
const formatter = new ExchNumberFormat('en-US', {
useCustomCurrency: true,
customCurrency: customCurrencyData,
currency: 'XCB'
});
console.log(formatter.format(1234.567)); // Outputs: '₡1,234.57'
Creates a new formatter instance configured with the specified locales and options.
locales
: A string with a BCP 47 language tag, or an array of such strings.options
: Configuration options for the formatter.Intl.NumberFormatOptions
.useAliases
: Enables the use of currency aliases.aliases
: Defines mappings from alias strings to standard currency codes.useCustomCurrency
: Enables the use of a custom currency dictionary.customCurrency
: Specifies custom currency settings.wrapped
: Indicates if the currency symbol should be wrapped with custom characters.wrappedSymbol
: The symbol used to wrap the currency symbol.digitized
: Indicates if the numeric values should be displayed with digital symbols.digitizedSymbol
: The symbol used to represent digitized values.roundingMode
: The rounding mode to use when formatting numbers.ceil
: Rounds numbers up.floor
: Rounds numbers down.expand
: Similar to ceil but expands beyond the typical rounding limits.trunc
: Truncates the number without rounding.halfCeil
: Rounds half values up.halfFloor
: Rounds half values down.halfExpand
: Expands half values during rounding.halfTrunc
: Truncates half values.halfEven
: Rounds half values to the nearest even number.Formats a number according to the instance's locale and formatting options.
Returns an array of objects representing the number string in parts that can be used for custom formatting.
Checks if the specified currency is supported by the formatter. Returns true
if the currency is supported, false
otherwise. If the formatter failed, an error is thrown.
Prints the version of the exchange-rounding
package.
Contributions are welcome! Feel free to open an issue or submit a pull request on our GitHub repository.
This project is licensed under the CORE License.
FAQs
Exchange Number Formatting
The npm package exchange-rounding receives a total of 59 weekly downloads. As such, exchange-rounding popularity was classified as not popular.
We found that exchange-rounding demonstrated a healthy version release cadence and project activity because the last version was released less than 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.