Answer the question
In order to leave comments, you need to log in
Converting a common fraction to a periodic decimal?
Good evening :)
Please help me with the translation of an ordinary fraction into a periodic decimal.
I use my methods of pairs - car, cdr. The result of addition of fractions does not suit because tests wait for record in the form of String.
Addition of fractions - pairs
export const sub = (pair, pair2) => (((car(pair) * (car(pair2)) + (cdr(pair) + cdr(pair2)))) / (cdr(pair) * car(pair2)));
export const toString = (pair) => (car(pair) + " / " + cdr(pair));
Answer the question
In order to leave comments, you need to log in
as an option use fraction.js
var f = new Fraction('88/33');
var c = f.toContinued(); // [2, 1, 2] в периоде 212212212212...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question