Skip to content

2.18.0

Latest

Choose a tag to compare

@bpierre bpierre released this 07 Oct 19:07
· 4 commits to main since this release
c4e6513

This version adds significantDigits to format(), making it easier to display small amounts without counting their leading zeros.

dn.format([126n, 8], { significantDigits: 1 }); // "0.000001"
dn.format([126n, 8], { significantDigits: 2 }); // "0.0000013"

Combine it with digits to keep normal decimal formatting while preserving more detail for small amounts:

dn.format([126n, 8], { digits: 2, significantDigits: 2 }); // "0.0000013"

It supports the existing rounding, trailing-zero, locale, and sign options. significantDigits must be a positive safe integer and cannot be combined with compact: true.

Also adds a README example showing how to read a token balance and pass a Dnum amount to a contract call.

See #27 and #26 for details.

Thanks @yodlmeister and @carpntr for the small-amount formatting suggestion and examples, and @elee1766 for suggesting the contract documentation 🙏