1.0.3 • Published 5 years ago

fractionalize v1.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

Fractions

npm version

Function that formats numbers to an approximate fraction

Install

npm install fractionalize

Usage

import {Fractionalize, FractionalizeOptions} from 'fractionalize';

const x = 2.4;
const xFormatted = Fractionalize(x);

Outputs: 2

Options

class FractionalizeOptions {
    maxDenominator=64;
    spaceBetweenIntegerAndFraction=true;
    tolerance=.01;
    exactMatch = false;
    showApproximationSymbol = false;
}

Supply a structure to the fractionalize function to fine tune the process.

  • maxDenominator - The highest number that would acceptable as a denominator in the fraction. Defaults to 64.
  • spaceBetweenIntegerAndFraction - Determines whether or not to place a space between the fraction and the integer portion of the number. Defaults to true
  • tolerance - if exactMatch is false, how close does the real number need to be to the fractional number to be used. Default is 1/100 (.01)
  • exactMatch - if true, the number will only be shown as a fraction if it exactly matches.
  • showApproximationSymbol - if true, and the fractional representation, show the ≈ symbol.