float-to-fraction

1.1.1 • Public • Published

A simple yet effective library to convert a float

3.6

To numerator/denominator

18/5

Written in C and exported to Node as a module.

npm install float-to-fraction 

In .js

const floatToFraction = require('float-to-fraction');

const float = 3.6;
const returnedArr = floatToFraction(float); //Returns [18, 5];

Note: the algorithm tries to find the smallest nominator/denominator relationship with the float applied. Most of the time the algorithm returns the correct fraction but it is not 100% accurate on every application, which depends on different factors like rational/irrational numbers and number of decimals.

The algorithm is based off: https://en.wikipedia.org/wiki/Continued_fraction

Readme

Keywords

none

Package Sidebar

Install

npm i float-to-fraction

Weekly Downloads

8

Version

1.1.1

License

ISC

Unpacked Size

35.8 kB

Total Files

10

Last publish

Collaborators

  • cajmorgan