//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>
我使用什么代码,所以我可以进行长达100个小数的分割?
答案 0 :(得分:1)
我不太确定你究竟需要什么,但以下功能可能有所帮助。默认情况下,它会在小数点后给出10位数,但如果指定100作为第三个参数,则应获得100位数。
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));