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 = half = half === 05 // truehalf === '1/2' // true === '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
- fraction arithmetic
- addition with
r.plus(x)
- subtraction with
r.minus(x)
- multiplication with
r.times(x)
- division with
r.div(x)
- reciprocal with
r.reciprocal()
- negative with
r.neg()
- addition with
still to come
- render unicode fractions?