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-01-10 11:09  丶凉雨拾忆  阅读(120)  评论(0编辑  收藏  举报