I am trying to solve a particular JavaScript exercise involving recurring numbers and in doing so I need to work with recurring numbers to a good amount of decimal places.
Currently I am using:
function divide(numerator, denominator){
var num = (numerator/parseFloat(denominator);
}
// 7/11 = 0.6363636363636364
// 5/3 = 1.6666666666666667
// 3/8 = 0.375
As you can see, the results of the operation that contain recurring digits are returned with the final digit rounded. It is tempting to simply convert to array and pop() the last digit of each number but this leads to problems when we run into numbers that are not recurring such as 3/8 =0.375.
How can I divide two numbers and get a result that such as 5/3 = 1.666666666666666 ? (essentially the last digit is rounded down and never rounded up)
Thanks for your help.