diff --git a/src/index.js b/src/index.js index e3308a3..0db22b7 100644 --- a/src/index.js +++ b/src/index.js @@ -62,9 +62,13 @@ export class Token { // return string format(number, decimals = this.decimals) { - return this.#iformat - .format(ethers.formatUnits(number, decimals)) - .replace('ETH', this.formatSymbol || this.symbol || this.name || '?') + const f = Number(ethers.formatUnits(number, decimals)) + const s = this.formatSymbol || this.symbol || this.name || '?' + return f > 0.1 + ? this.#iformat + .format(ethers.formatUnits(number, decimals)) + .replace('ETH', s) + : `${s} ${f}` } // return BigInt diff --git a/test/erc.spec.js b/test/erc.spec.js index c4dad8f..2f93327 100644 --- a/test/erc.spec.js +++ b/test/erc.spec.js @@ -157,12 +157,17 @@ describe('TokenERC20Amount', function () { }) // TODO -describe('Misc', function () { - it('xxx', async function () { - console.log(ethers.formatUnits('1000000000000', 18)) - const amountA = await TokenAmount.from(usdc, 3) +xdescribe('Misc', function () { + it('big', async function () { + const amountA = await TokenAmount.from(usdc, 100000) + console.log(amountA.toFloat()) + console.log(amountA.toString()) + }) + it('small', async function () { + const amountA = await TokenAmount.from(usdc, 0.00001) console.log(amountA.toFloat()) + console.log(amountA.toString()) }) })