num[];//为这个数组;
arrayValue() {
for (var j = 0; j <= this.num.length - 1; j++) {
for (var i = this.num.length - 2 - j; i >= 0; i--) {
this.num[j] = this.num[j] * 10;
}
this.numValue = this.numValue + this.num[j];
}
//以上是把每次输入的数字加入到数组,然后算他们的值;
}
以上是【1,2,3,4,5】转成 12345 的方法。
接下来讲的是:【1,2,‘.’,3,4】转成12.34的方法
dotBefore;//整数部分
dotAfter;//小数部分
hasDotArray() {
this.numValue = 0;
this.num.forEach(i => {
if (this.num[i] == '.') {
this.k = i;
}
});
//先找到小数点的位置k
var l = this.k - 1;
var m = 1;
for (var j = 0; j <= this.num.length - 1; j++) {
//先计算点之前的和
if (j < this.k) {
for (var n = l; n > 0; n--) {
this.num[j] = this.num[j] * 10;
}
this.dotBefore = this.dotBefore + this.num[j];
l = l - 1;
}
//再计算点之后的和
if (j > this.k) {
for (var o = m; o >0; o--) {
this.num[j] = this.num[j]/ 10;
}
this.dotAfter = this.dotAfter + this.num[j];
m = m + 1;
}
}
this.numValue = this.dotBefore + this.dotAfter;
}