壮壮灬

 

js数字千位符

1、方法

const formatThousand = data => {
  let type = Object.prototype.toString.call(data);
  if (type === "[object Number]") {
    return data
      .toString()
      .replace(/(^|\s)\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ","));
  } else {
    return data;
  }
};

2、例

posted on 2022-04-02 16:43  壮壮灬  阅读(172)  评论(0编辑  收藏  举报

导航