bgl-units
v1.0.1
Published
Convert Satoshi units <-> BGL
Downloads
7
Maintainers
Readme
bgl-units
npm module to convert between Satoshi units(smallest denomination for Bitgesell BGL) and BGL with lightweight precision.
The Problem
Install
npm install --save bgl-units
# OR
yarn add bglunits
Usage
Node.js
const bglunits= require("bgl-units");
bglunits.toSatoshiUnits(1);
//=>100 000 000
bglunits.toBGL(100000000);
//=>1
Web
<!-- package injected as "bglunits" -->
<script src="https://rawgit.com/naftalimurgor/bglunits/master/index.bundle.js"></script>
<script>
console.log("One Satoshi equals " + bglunits.toBitcoin(1) + " Bitcoin");
</script>
Or download it with npm install bgl-units
and reference it as:
<script src="node_modules/bglunits/index.bundle.js"></script>
Error Handling
try {
bglunits.toSatoshiUnits(false); //Throws TypeError
} catch (err) {
console.log(err);
}
API
bglunits.toSatoshiUnits(number || string)
bglunits.toBGL(number || string)
FAQ
What is a Satoshi?
- Satoshi is to Bitcoin as pennies are to the dollar. Except that there are 100,000,000 Satoshi in one Bitcoin.
Why do I need a module when I can just divide or multiply by 100,000,000?
- See here - Floating point errors are a problem. So
bgl-units
uses a tiny bignum library (big.js) to ensure accurate conversions!
- See here - Floating point errors are a problem. So
Tests
npm test