fracjs
v1.0.5
Published
A JavaScript library to solve precision problem
Downloads
7
Readme
Fraction
A simple math library to solve precision problem
Getting Started
Include Fraction
in your project:
<script src="dist/fraction.min.js"></script>
Usage
Create the Fraction
object with a starting value, it can be a string
version of number. Then you can call any Fraction
methods on created math object, it will modify the value in place
let math = Fraction(0.1);
math.add(0.1);
math.add(0.1);
console.log(math.value); // 0.3
There is a method also available to create Fraction
object, which will create and return a new Fraction
object.
let currency = Fraction(0.1);
You can also chain methods. The toString
method returns the value from Fraction
object, so if you are explicitly or implicitly converting Fraction
object to a string that will return the value.
let currency = fraction(0.1)
.add(0.1)
.add(0.1)
.divide(Fraction.PI);
console.log(`value: ${currency}`);