小数点后保留两位,整数和小数通用

toDemical(val) {
	let valNew = Math.round(parseFloat(val) * 100) / 100;
	let splitVal = valNew.toString().split(".");
	if (splitVal.length == 1) {
		valNew = valNew.toString() + ".00";
		return valNew;
	}
	if (splitVal.length > 1) {
		if (splitVal[1].length < 2) {
			valNew = valNew.toString() + "0";
		}
		return valNew;
	}
}

  

上一篇:TypeScript


下一篇:c语言逆序输出三位数整数