經常使用正則表達式總結

前三位加逗號

export const formatMoney = (str) => {
    str = Number(str).toFixed(2);
    return str.replace(/\B(?=(\d{3})+($|\.))/g, ',');
};
相關文章
相關標籤/搜索