All files / src/utils/math index.js

20% Statements 2/10
0% Branches 0/6
0% Functions 0/2
20% Lines 2/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 157x                   7x        
export const roundToFirst = (num) => {
    if (num >= 1) {
        const power = Math.pow(10, String(Math.round(num)).length - 1);
        return Math.round(num / power) * power;
    } else if (num > 0)
        return +num.toFixed(String(num).match(/^0\.0*/)[0].length - 1);
    else // 不解决0或负数
        return num;
};
 
export const getFixedCount = (num) => {
    const m = String(num).match(/\.\d+/);
    return m ? m[0].length - 1 : 0;
};