Skip to content

Instantly share code, notes, and snippets.

@nanoaquila
Created December 5, 2017 11:44
Show Gist options
  • Save nanoaquila/2d0a3002c46e384aa2f9f41539d17bb1 to your computer and use it in GitHub Desktop.
Save nanoaquila/2d0a3002c46e384aa2f9f41539d17bb1 to your computer and use it in GitHub Desktop.
function calculateOddsDecimal(a, b) {
return (a / b);
}
function calculateOddsPercent(a, b) {
return (calculateOddsDecimal(a, b) * 100).toFixed(2);
}
function fractionToDecimal(fraction) {
let fractional = fraction.split('/');
return fractional[0] / fractional[1];
}
function decimalToFraction(decimal) {
let gcds = gcd(decimal * 100, 100);
return `${((decimal * 100) / gcds)}/${(100 / gcds)}`;
}
function gcd(numerator, denominator) {
if (!denominator) {
return numerator;
}
return gcd(denominator, numerator % denominator);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment