1.取模求余数
//1.JS取模求余
//输出
for (var i = 0; i < 20; i++) {
if (i % 3 == 0) {
documentHelper.WriteText(i + "是3的倍数");
}
}
2.四舍五入
//1.四舍五入函数toFixed(),里面的参数就是保留小数的位数
var numberOne = 2.15121618;
documentHelper.WriteText("保留一位小数:" + numberOne.toFixed(1));
documentHelper.WriteText("保留两位小数:" + numberOne.toFixed(2));
documentHelper.WriteText("保留四位小数:" + numberOne.toFixed(4));
//2.四舍五入函数Math.round(number),取整四舍五入
documentHelper.WriteText("1.5四舍五入:" + Math.round(1.5));
documentHelper.WriteText("1.09四舍五入:" + Math.round(1.09));
documentHelper.WriteText("-1.9四舍五入:" + Math.round(-1.9));