数字千位分隔

来源:互联网 发布:北京曹庆民曹氏推算法 编辑:程序博客网 时间:2024/04/30 09:23
//千位分隔符
    function cc(s) {
        s=s.toString();
        if (/[^0-9\.]/.test(s)) return s;
        s = s.replace(/^(\d*)$/, "$1.");
        s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
        s = s.replace(".", ",");
        var re = /(\d)(\d{3},)/;
        while (re.test(s))
            s = s.replace(re, "$1,$2");
        s = s.replace(/,(\d\d)$/, ".$1");
        return s.replace(/^\./, "0.")
    }




//千位分隔
        protected string GetthousandseparatorNum(object str)
        {
            if (!string.IsNullOrEmpty(str.ToString()))
            {
                double i = Convert.ToDouble(str);
                return string.Format("{0:N}", i);
            }
            else
            {
                return str.ToString();
            }
        }
0 0
原创粉丝点击