Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shesek/fmtbtc
Format and convert bitcoin's display units (msat, sat, bit, milli and btc)
https://github.com/shesek/fmtbtc
bit bitcoin bitcoin-units bits btc milli millis msat msatoshi sat satoshi
Last synced: 14 days ago
JSON representation
Format and convert bitcoin's display units (msat, sat, bit, milli and btc)
- Host: GitHub
- URL: https://github.com/shesek/fmtbtc
- Owner: shesek
- Created: 2018-03-16T03:22:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-03-17T00:31:17.000Z (over 6 years ago)
- Last Synced: 2024-10-28T12:24:52.921Z (20 days ago)
- Topics: bit, bitcoin, bitcoin-units, bits, btc, milli, millis, msat, msatoshi, sat, satoshi
- Language: JavaScript
- Homepage:
- Size: 59.6 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# fmtbtc
Format and convert bitcoin's display units (`msat`, `sat`, `bit`, `milli` and `btc`).
Operates on the numbers as strings using [move-decimal-point](https://github.com/shesek/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.## Install
```bash
$ npm install fmtbtc
```## Use
```js
// common case: convert from satoshis to btc
import fmtbtc from 'fmtbtc'
fmtbtc(100000000) // => 1
fmtbtc(100000005000) // => 1000.0005// pretty print with commas separator
fmtbtc(100000005000, true) // => 1,000.0005// with other base/target units
import { msat2milli, milli2msat } from 'fmtbtc'
msat2milli(100000000) // => 1
milli2msat(1, true) // => 100,000,000// with dynamic unit names via fmt()/pfmt()
import { fmt, pfmt } from 'fmtbtc'
fmt(1, 'milli', 'sat') // => 100000
pfmt(1, 'milli', 'sat') // => 100,000
```Using the browserify bundle (available at `dist/fmtbtc.bundle.min.js`),
which exposes the library at `window.fmtbtc`:```html
fmtbtc(100000000) // => 1
fmtbtc.sat2milli(100000) // => 1```
## License
MIT