// 去掉第一位为0或者.
function delectezero() {
// 整单折扣去第一位0
// 这里一定要转为字符串
this.totals = this.totals.toString();
this.off_price = this.off_price.toString();
this.offs = this.offs.toString();
// 去掉第一位的0或则’.’ 截取从下表1到最后一位,返回一个新数组。
while ((this.totals.charAt(0) == ‘0’ || this.totals.charAt(0) == ‘.’) || (this.off_price.charAt(0) == ‘0’ || this.off_price.charAt(0) == ‘.’) || (this.offs.charAt(0) == ‘0’ || this.offs.charAt(0) == ‘.’)) {
if (this.totals.charAt(0) == ‘0’ || this.totals.charAt(0) == ‘.’) { // 折后应收金额
if (this.totals.length > 1) {
this.totals = this.totals.substring(1, this.totals.length);
} else {
break;
}
// charAt(i) 返回指定位置的字符,返回的字符是长度为 1 的字符串
} else if (this.off_price.charAt(0) == ‘0’ || this.off_price.charAt(0) == ‘.’) { // 折扣金额
if (this.off_price.length > 1) {
this.off_price = this.off_price.substring(1, this.off_price.length);
} else {
break;
}
} else if (this.offs.charAt(0) == ‘0’ || this.offs.charAt(0) == ‘.’) { // 折扣率
if (this.offs.length > 1) {
this.offs = this.offs.substring(1, this.offs.length);
} else {
break;
}
}
}
js去掉字符串第一位的0或者‘.‘
最新推荐文章于 2023-11-24 11:47:43 发布