千分位转数字,数字转千分位

<script>
        class strNumSwitch {
            // 千分转数字
            static toNum = (param) => {
                let num = param
                if (`${param}`.includes(',')) {
                num = param.replace(/(,*)/g, '')
                }
                if (isNaN(Number(num))) {
                num = 0
                }
                return Number(num)
            }
            // 数字转千分
            static toStr = (param) => {
                const str = param.replace(/(,*)/g, '')
                const num = `${str}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
                return num
            }
        }

    </script>
posted @ 2020-08-27 14:43  国服第一李师师  阅读(208)  评论(0编辑  收藏  举报