美文网首页
vue 关于千分位的分割

vue 关于千分位的分割

作者: 你的名字97 | 来源:发表于2021-08-17 17:06 被阅读0次

数据处理列子  输入1000,生成["1", ",", "0", "0", "0"]

function toJson (num) {

            var a = (num + '').split('')

            var all = []

            a.map((item, index) => {

                all.push(item)

            })

            if (all.length > 3) {

                const num = Math.ceil((all.length - 3) / 3)

                if (num) {

                    for (let i = 0; i < num; i++) {

                        all.splice(all.length - 3 - i - 3 * i, 0, ',')

                    }

                } else {

                    all.splice(num, 0, ',')

                }

            }

          console.log(all)

        },

相关文章

网友评论

      本文标题:vue 关于千分位的分割

      本文链接:https://www.haomeiwen.com/subject/qzjibltx.html