1.0.5 • Published 5 years ago

fracjs v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Build Status License Version

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}`);
1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago