Skip to content

Function: round() ​

ts
function round(value, decimals?): number;

Round to decimals places without classic float artifacts (e.g. 1.005 → 1.01). 按小数位四舍五入,避免 1.005 变成 1.00 等问题。

Parameters ​

ParameterTypeDefault valueDescription
valuenumberundefinedNumber to round / 待舍入的数
decimalsnumber0Decimal places (default 0) / 保留小数位,默认 0

Returns ​

number

Rounded number / 舍入结果

Example ​

ts
round(1.005, 2) // => 1.01

Since ​

1.0.0

Released under the MIT License.