Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Repeating Decimals by mozurin
"use strict";
function convert(numerator, denominator)
{
const quotients = [];
const remainders = [0];
while (true)
{
quotients.push(Math.floor(numerator / denominator));
numerator = (numerator % denominator) * 10;
if (remainders.includes(numerator)) {
if (numerator) {
quotients.splice(
remainders.lastIndexOf(numerator) - remainders.length,
0,
'('
);
quotients.push(')');
}
break;
}
remainders.push(numerator);
}
return `${quotients[0]}.${quotients.slice(1).join('')}`;
}
July 26, 2018