npm module to convert between Satoshi units(smallest denomination for Bitgesell BGL) and BGL with lightweight precision.
npm install --save bgl-units
# OR
yarn add bglunits
var bglunits= require("bgl-units");
bglunits.toSatoshiUnits(1);
//=>100000000
bglunits.toBGL(100000000);
//=>1
<!-- 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>
try {
bglunits.toSatoshiUnits(false); //Throws TypeError
} catch (err) {
console.log(err);
}
bglunits.toSatoshiUnits(number || string)
bglunits.toBGL(number || string)
-
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
npm test