Wie fügt man in JavaScript ein Komma an die tausendste Stelle eines ganzzahligen Betrags hinzu?

    // 整数千分位添加逗号
    function toThousands(num) {
    
    
        num = num.toString()
        let result = '';
        while (num.length > 3) {
    
    
            result = ',' + num.substring(num.length - 3) + result;
            num = num.substring(0, num.length - 3);
        }
        result = num + result;
        return result;
    }

Der Effekt ist wie in der Abbildung dargestellt:

Ganzzahlige Tausendstel fügen Komma-Renderings hinzu

おすすめ

転載: blog.csdn.net/xiaorunye/article/details/129868608