You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
481 B
17 lines
481 B
var gcd = require('./gcd'); |
|
var precision = require('./precision'); |
|
exports = function(num) { |
|
if (num === 0) return '0'; |
|
var _precision = precision(num); |
|
_precision = pow(10, _precision); |
|
var numerator = num * _precision, |
|
denominator = _precision; |
|
var _gcd = abs(gcd(numerator, denominator)); |
|
numerator /= _gcd; |
|
denominator /= _gcd; |
|
return numerator + '/' + denominator; |
|
}; |
|
var abs = Math.abs; |
|
var pow = Math.pow; |
|
|
|
module.exports = exports;
|
|
|