小数点四舍五入测试

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
基本方法
function ceilToTwoDecimals(num) {
    return Math.ceil(num * 100) / 100;
}
ready
处理边缘情况的完整函数
function ceilToTwoDecimals(num) {
    if (typeof num !== 'number' || isNaN(num)) {
        return NaN;
    }
    
    // 处理正负数
    const factor = 100;
    return Math.ceil(num * factor) / factor;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.