Skip to content

@pmun/utils / round

Function: round()

ts
function round(num, precision): number;

将数字四舍五入到指定小数位

Parameters

num

number

要处理的数字

precision

number = 0

小数位数,默认为0(整数)

Returns

number

四舍五入后的数字

Example

ts
round(3.1415) // 3
round(3.1415, 2) // 3.14
round(3.1415, 3) // 3.142
round(3.9999) // 4