R
R
Rishat Sultanov2017-07-15 18:45:47
JavaScript
Rishat Sultanov, 2017-07-15 18:45:47

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)));

toString is a fraction in a clear form:
export const toString = (pair) => (car(pair) + " / " + cdr(pair));

I want to make the addition method return a pair (numerator, denominator)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ernest Fayzullin, 2017-07-16
@rishatss

as an option use fraction.js

var f = new Fraction('88/33');
var c = f.toContinued(); // [2, 1, 2] в периоде 212212212212...

There are many more useful features

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question