fraction.js

fraction.js is a fraction library written in javascript. With it you can comfortably create and manipulate fractions from Javascript.

Usage:
js> load('fraction-0.2.js'); // creates the global Fraction object

js> (new Fraction(7,3)).multiply(new Fraction(1,2))
1 1/6
js> (new Fraction(7,3)).divide(new Fraction(1,2))
4 2/3
js> (new Fraction(3,10)).add(new Fraction(5,9))
77/90
js> (new Fraction(0.25)).add(new Fraction(1,6))
5/12
js> (new Fraction(0.35)).subtract(new Fraction(1,4))
1/10

Development: github (This is the best way to get fraction.js)
Download: releases - v0.3 is current
Open source: MIT license
Author: Erik Garrison; contact: erik at hypervolu dot me

Notes

Release History

  • 0.3 2010-02-18 - Rounding issue resolution and speed tweak.
  • 0.2 2009-11-19 - Major cleanup, resolution of namespace issues.
  • 0.1 2009-10-30 - Basic functionality. Issues with namespacing (use of array mixins, other problems).