bitcoin-math
Providesw number prototypes for converting between BTC and Satoshi values. It uses string based parsing, which avoids JavaScript's nasty problem of doing weird things with integer division.
Also adds a zeropad method for making full length BTC strings
If imported and used as var btcMath = require('bitcoin-math')
you can use
btcMath.getRandomBitcoin() and btcMath.getRandomSatoshi(). If you do not need
these, you can simply import the module without assigning it to a variable and
still use the number prototypes.
TOC
Number.toBitcoin()
should add the toBitcoin function to the Number object.
var num = 1;;
should return a bitcoin value derived from the number.
var satoshi = 10000000;;
should return NaN if the original is NaN.
var bad = NaN;;
Number.toSatoshi()
should add the toSatoshi function to the Number object.
var num = 1;;
should return a satoshi value derived from the number.
var bitcoin = 1;;
should return NaN if the original is NaN.
var bad = NaN;;
Number.zeroFill()
should add the zeroFill function to the Number object.
var num = 1;;
should return a decimal with zeros added (1 => 1.00000000).
var bitcoin = 1;;
should return a decimal with zeros added (1.123 => 1.12300000).
var bitcoin = 1123;;
should return NaN if the original is NaN.
var bad = NaN;;
#getRandomSatoshi()
should reurn an integer value between the specified values with specified non zero digits.
var rand = btcMath;;;var nonZeros = randlength;;
#getRandomBitcoin()
should reurn a float value between the specified values with specified non zero digits.
var rand = btcMath;;;var nonZeros = randlength;;