-1
//NumberPair.js 
   class NumberPair{
    constructor(a,b){
        console.log("ik besta",a,b);
        this.a = a;
        this.b = b;
    }
    division(){
        return this.a / this.b;
    }
    longDivision(){
        var ans;
        var floor = Math.floor(this.a/this.b);
        var mod = this.a % this.b;
        ans = floor + ".";
        for(i=0;1<100;i++){

        }

        return ans;
    }
}
//script.js
var numbers = new NumberPair(15,7);

console.log(numbers.longDivision());
//index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Divisors</title>
  </head>
  <body>
    <h1>LongDivision</h1>
    <div id="content"></div>
    <script type="text/javascript" src="../../lib/Number.js"></script>
    <script type="text/javascript" src="../../lib/NumberPair.js"></script>
    <script type="text/javascript" src="script.js"></script>
  </body>
</html>

What code do I use so I could make a long division that goes up to 100 decimals?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
MrTopGamer
  • 13
  • 1
  • Have you done any research and made any attempts to solve this problem? [How to Ask](http://stackoverflow.com/help/how-to-ask). Also, what's this bit in the for loop supposed to do? `for(i=0;1<100;i++)`? Shouldn't it be `i<100`? Anyway, tip to get you started: change `ans` inside the for loop. – AgataB Oct 02 '16 at 12:17

1 Answers1

1

I am not too sure what exactly you need but the following function might help. It will by default give you 10 digits after decimal point but if you specify 100 as the third argument you shall get 100 digits.

var longDivision = (a,b,n=10,ds=".") => n ? Math.floor(a/b) + ds + longDivision(a%b*10,b,--n,"") : "";

console.log(longDivision(857,7,100));
Redu
  • 25,060
  • 6
  • 56
  • 76