Package Exports
- bgl-units
- bgl-units/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bgl-units) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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 bglunitsUsage
Node.js
const bglunits= require("bgl-units");
bglunits.toSatoshiUnits(1);
//=>100 000 000
bglunits.toBGL(100000000);
//=>1Web
<!-- 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-unitsuses a tiny bignum library (big.js) to ensure accurate conversions!
- See here - Floating point errors are a problem. So
Tests
npm test