节点货币
安装
运行以下命令
npm install --save @coinify/currency
使用量
const currency = require('@coinify/currency');
currency 暴露以下功能:
getDecimalsForCurrency(currency)
返回浮动点后的小数,根据币种的不同,该数值应当与该数字格式化.
fromSmallestSubunit(amount, currency)
从货币中最小的子单位转换到主单位的金额.
toSmallestSubunit(amount, currency)
将货币主单位的一定金额转换为最小分单位.
convertSubunitAmount(amountSubUnit, rate, fromCurrency, toCurrency)
以给定的汇率在子单位之间转换两种货币的金额,在小数不同的子单位之间正确转换.
computeRateBetweenSubunitAmounts(fromCurrency, fromAmount, toCurrency, toAmount)
以两种不同的货币计算两个数额之间的汇率.
isValidCurrency(code)
所提供的货币编码是否为有效货币? (虚构或加密)
isValidFiatCurrency(code)
所提供的货币编码是否为有效的无价货币?
isValidCryptoCurrency(code)
所提供的货币编码是否为有效的加密货币?