Skip to content

toFixed

保留小数。

基本用法

传入要处理的数和精度,返回指定精度的数。默认四舍五入,可以设置rounded取消四舍五入。

ts
import { toFixed } from '@renzp/number-correct'

toFixed(5.33333333, 0); // 5
toFixed(5.33333333, 2); // 5.33
toFixed(5.66666666, 2); // 5.67
toFixed(5.66666666, 2, false); // 5.66

参数

参数说明类型默认值是否必填
number要处理的数Value-
precision精度(为0则表示只保留整数)number-
rounded是否四舍五入booleantrue
ts
type Value = string | number

返回

参数说明类型
v指定精度的数string