functionKeepDecimalPlace(num, n)local temp =10^(-n)
num = num - num % temp
return num
endprint(KeepDecimalPlace(0.1234,3))---打印:0.123
二、四舍六入五成双?
functionKeepDecimalPlace(num, n)local format ="%."..n.."f"
num = string.format(format, num)return num
endprint(KeepDecimalPlace(0.1274,3))---打印:0.127 四舍print(KeepDecimalPlace(0.1236,3))---打印:0.124 六入print(KeepDecimalPlace(0.12451,3))---打印:0.125 五后面有数就入print(KeepDecimalPlace(0.12450,3))---打印:0.124print(KeepDecimalPlace(0.1245,3))---打印:0.124print(KeepDecimalPlace(0.1255,3))---打印:0.126 第3位是5时开始判断进位print(KeepDecimalPlace(0.1265,3))---打印:0.127print(KeepDecimalPlace(0.1275,3))---打印:0.128