toFixed
liz-q 2024/1/11
数字四舍五入保留指定精度
toFixed(num, digit = 2, isOriginal = false)
# 参数
num
(number):需要保留精度的数字digit
(number):精度,就是小数后几位isOriginal
(boolean):是否使用原生 toFixed 四舍五入机制(银行家舍入法),默认为 false
# 返回值
(number | boolean):返回处理后的数字,如果传入非法数字返回 false
# 例子
import { toFixed } from '@liz-q/utils'
toFixed(13.5665, 3) // 13.567
toFixed(13.5665, 3, true) // 13.566 这是银行家舍入