@helium/currency
Advanced tools
Comparing version
import BigNumber from 'bignumber.js'; | ||
import { AnyCurrencyType } from './CurrencyType'; | ||
import { NetworkTokens, USDollars, DataCredits, BaseCurrencyType } from './currency_types'; | ||
declare type StringFormatOptions = { | ||
decimalSeparator?: string; | ||
groupSeparator?: string; | ||
showTicker?: boolean; | ||
}; | ||
export default class Balance<T extends BaseCurrencyType> { | ||
@@ -12,3 +17,3 @@ type: T; | ||
static fromFloat(float: number, currencyType: AnyCurrencyType): Balance<AnyCurrencyType>; | ||
toString(maxDecimalPlaces?: number): string; | ||
toString(maxDecimalPlaces?: number, options?: StringFormatOptions): string; | ||
plus(balance: Balance<T>): Balance<T>; | ||
@@ -22,2 +27,3 @@ minus(balance: Balance<T>): Balance<T>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=Balance.d.ts.map |
@@ -36,13 +36,18 @@ "use strict"; | ||
} | ||
toString(maxDecimalPlaces) { | ||
let numberString = this.bigBalance.toFormat(maxDecimalPlaces); | ||
toString(maxDecimalPlaces, options) { | ||
const decimalSeparator = (options === null || options === void 0 ? void 0 : options.decimalSeparator) || '.'; | ||
const groupSeparator = (options === null || options === void 0 ? void 0 : options.groupSeparator) || ','; | ||
const showTicker = (options === null || options === void 0 ? void 0 : options.showTicker) === undefined ? true : options.showTicker; | ||
let numberString = maxDecimalPlaces | ||
? this.bigBalance.toFormat(maxDecimalPlaces, { decimalSeparator, groupSeparator, groupSize: 3 }) | ||
: this.bigBalance.toFormat({ decimalSeparator, groupSeparator, groupSize: 3 }); | ||
// if it's an integer, just show the integer | ||
if (parseInt(numberString.split('.')[1]) === 0) { | ||
numberString = numberString.split('.')[0]; | ||
if (parseInt(numberString.split(decimalSeparator)[1], 10) === 0) { | ||
[numberString] = numberString.split(decimalSeparator); | ||
} | ||
// if the rounded amount is 0, then show the full amount | ||
if (numberString === '0') { | ||
numberString = this.bigBalance.toFormat(); | ||
numberString = this.bigBalance.toFormat({ decimalSeparator, groupSeparator }); | ||
} | ||
return [numberString, this.type.ticker].join(' '); | ||
return showTicker ? [numberString, this.type.ticker].join(' ') : numberString; | ||
} | ||
@@ -49,0 +54,0 @@ plus(balance) { |
{ | ||
"name": "@helium/currency", | ||
"version": "3.16.0", | ||
"version": "3.23.0", | ||
"description": "Utilities for handling different currency types on the Helium blockchain", | ||
@@ -31,3 +31,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "e764bb372ca18d2709ea22d0b8c84d77d35739aa" | ||
"gitHead": "4b6c414a1745a51746a3f9a0c0c9a3a7d699a327" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42025
3.77%315
3.62%