bgl-units

1.0.0 • Public • Published

bgl-units

npm module to convert between Satoshi units(smallest denomination for Bitgesell BGL) and BGL with lightweight precision.


The Problem

The problem


Install

npm install --save bgl-units

# OR

yarn add bglunits

Usage

Node.js

var bglunits= require("bgl-units");

bglunits.toSatoshiUnits(1);
//=>100000000

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)

Read more on the Wiki


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!

Tests

npm test

License

MIT © Forked from: Dawson Botsford

Package Sidebar

Install

npm i bgl-units

Weekly Downloads

5

Version

1.0.0

License

MIT

Unpacked Size

38.9 kB

Total Files

5

Last publish

Collaborators

  • naftalimurgor