![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
bitcoin-units
Advanced tools
Convert between any bitcoin unit - BTC, mBTC, μBTC, satoshi and even your own custom units! Available for ES6 and Node.js.
bitcoin(1, 'mBTC').to('BTC').value()
0.001
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001 BTC'
Add bitcoin-units
to your Javascript project dependencies using Yarn:
yarn add bitcoin-units
Or NPM:
npm install bitcoin-units --save
Import using ES6:
import bitcoin from 'bitcoin-units';
Or AMD:
var bitcoin = require('bitcoin-units');
Basic unit conversions are done using the to(unit)
function:
bitcoin(1, 'mBTC').to('BTC').value()
0.001
There are 4 available units by default:
btc
, mbtc
, bit
and satoshi
.
You can also use any of the following aliases:
btc
: bitcoin
or bitcoins
mbtc
: millibtc
bit
: μbtc
or microbtc
satoshi
: sat
, sats
, satoshi
, satoshis
value()
returns a Number
:
bitcoin(1, 'mBTC').to('BTC').value()
0.001
toString()
returns a string
:
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001'
format()
returns a string with the value and unit:
bitcoin(100000, 'satoshi').to('BTC').format()
'0.001 BTC'
You can set your own custom units using the bitcoin.setDisplay(unit, options)
:
bitcoin.setDisplay('satoshi', {
format: '{amount} custom'
});
bitcoin(1, 'BTC').to('satoshi').format();
'100,000,000 custom'
If you want to create your own custom units, you can use the bitcoin.setUnit(unit, value)
:
bitcoin.setUnit('custom', 1 / 1E2);
bitcoin(1, 'btc').to('custom').value();
100
You can use this to create your own conversion to fiat currencies:
// Let's suppose a rate of 1 BTC = $8000.00
bitcoin.setUnit('usd', 1 / 8000);
bitcoin(1, 'satoshi').to('usd').value();
0.00008
There's a shorthand to this function named bitcoin.setFiat(unit, rate)
:
bitcoin.setFiat('usd', 8000);
bitcoin(1, 'satoshi').to('usd').value();
0.00008
Rui Gomes
https://ruigomes.me
The MIT License (MIT). Please see LICENSE file for more information.
FAQs
Convert between BTC, mBTC, μBTC, satoshis and custom units.
The npm package bitcoin-units receives a total of 341 weekly downloads. As such, bitcoin-units popularity was classified as not popular.
We found that bitcoin-units demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.