Skip to content

numberFormatter方法有问题 #2568

@luocong2016

Description

@luocong2016

Bug report(问题描述)

export function numberFormatter(num, digits) {
    const si = [
        { value: 1e18, symbol: "E" }, 
        { value: 1e15, symbol: "P" },
        { value: 1e12, symbol: "T" },
        { value: 1e9, symbol: "G" },
        { value: 1e6, symbol: "M" },
        { value: 1e3, symbol: "k" }
    ];
    for (let i = 0; i < si.length; i++) {
        if (num >= si[i].value) {
            return (num / si[i].value + 0.1).toFixed(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, "$1") + si[i].symbol;
        }
    }
    return num.toString();
}

Steps to reproduce(问题复现步骤)

这个方法错误:

  1. numberFormatter(100000, 2) => "100.1k"

Screenshot or Gif(截图或动态图)

Link to minimal reproduction(最小可在线还原demo)

Other relevant information(格外信息)

  • Your OS:
  • Node.js version:
  • vue-element-admin version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions