ratio
v0.0.1
Published
Rational numbers (fractions)
Downloads
6
Readme
ratio - ℚ in JS
Sometimes you want to handle a ratio as its own entity. Yeah, you could downcast to decimal (though on floating point that's really a crime), or encode it as a string, but neither of those really cuts it.
So why not npm install ratio
?
var ratio = require('ratio')
, half = ratio(4,8)
half === 0.5 // true
half.toString() === '1/2' // true
ratio(0.02).toSring() === '1/50'
features
- flexible instantiation:
- from numerator and denominator
- from string
- from decimal number
- nice rendering
valueOf()
returns numeric formtoString()
renders fractional form
- automatically reduces fractions on creation
still to come
- arithmetic (r.plus/minus/times/div)
- reciprocal
- render unicode fractions?