Format and convert bitcoin's display units (msat, sat, bit, milli and btc).
Operates on the numbers as strings using move-decimal-point (the only dependency), so that it doesn't require a library for arbitrary-precision arithmetic.
The browserify bundle (including the move-decimal-point dependency) weights 1,781 bytes when minified
or 868 bytes when gzipped.
$ npm install fmtbtc// common case: convert from satoshis to btcimportfmtbtcfrom'fmtbtc'fmtbtc(100000000)// => 1fmtbtc(100000005000)// => 1000.0005// pretty print with commas separatorfmtbtc(100000005000,true)// => 1,000.0005// with other base/target unitsimport{msat2milli,milli2msat}from'fmtbtc'msat2milli(100000000)// => 1milli2msat(1,true)// => 100,000,000// with dynamic unit names via fmt()/pfmt()import{fmt,pfmt}from'fmtbtc'fmt(1,'milli','sat')// => 100000pfmt(1,'milli','sat')// => 100,000Using the browserify bundle (available at dist/fmtbtc.bundle.min.js),
which exposes the library at window.fmtbtc:
<scriptsrc="fmtbtc.bundle.min.js"></script><script>fmtbtc(100000000)// => 1fmtbtc.sat2milli(100000)// => 1</script>MIT