round
将数字四舍五入到指定精度。
199 bytes
since v12.2.0
使用方法
_.round 函数将给定数字四舍五入到指定精度。
import * as _ from "radashi";
_.round(123.456); // => 123_.round(1234.56, -2); // => 1200精度
precision 参数被限制在-323 到+292 的范围内。没有这个限制,此范围之外的精度值可能导致 NaN。
四舍五入方法
您可以提供自定义的四舍五入方法。默认是 Math.round。
_.round(4.001, 2, Math.ceil); // => 4.01_.round(4.089, 2, Math.floor); // => 4.08