Skip to content

Methodiseme/monero-math

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

monero-math

Provides number prototypes for converting between XMR 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 XMR strings

TOC

Number.toMonero()

should add the toMonero function to the Number object.

var num = 1;
assert(num.toMonero);

should return a monero value derived from the number.

var satoshi = 100000000000;
assert(satoshi.toMonero() === 0.1);

should return NaN if the original is NaN.

var bad = NaN;
assert(isNaN(bad.toMonero()));

Number.toSatoshi()

should add the toSatoshi function to the Number object.

var num = 1;
assert(num.toSatoshi);

should return a satoshi value derived from the number.

var monero = 1;
assert(monero.toSatoshi() === 1000000000000);

should return NaN if the original is NaN.

var bad = NaN;
assert(isNaN(bad.toSatoshi()));

Number.zeroFill()

should add the zeroFill function to the Number object.

var num = 1;
assert(num.zeroFill);

should return a decimal with zeros added (1 => 1.000000000000).

var monero = 1;
assert(monero.zeroFill() === "1.000000000000");

should return a decimal with zeros added (1.123 => 1.123000000000).

var monero = 1.123;
assert(monero.zeroFill() === "1.123000000000");

should return NaN if the original is NaN.

var bad = NaN;
assert(isNaN(bad.zeroFill()));

About

JS math for XMR and Satoshi values

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%