码迷,mamicode.com
首页 > Windows程序 > 详细

c#及js实现将金融变成3位一逗号

时间:2016-08-17 13:35:34      阅读:301      评论:0      收藏:0      [点我收藏+]

标签:

1、c#用string.format

ToString("#,###.00")

2、js方法 转自http://www.cnblogs.com/cssfirefly/p/3582027.html

(1)

 var   num_s = "1232134456.546 ";
    alert(parseFloat(num_s).toLocaleString());
(2)
 function format_number(nStr ){
        nStr += ‘‘;  
        x = nStr.split(‘.‘);  
        x1 = x[0];  
        x2 = x.length > 1 ? ‘.‘ + x[1] : ‘‘;  
        var rgx = /(\d+)(\d{3})/;  
        while (rgx.test(x1)) {  
            x1 = x1.replace(rgx, ‘$1‘ + ‘,‘ + ‘$2‘);  
        }  
        return x1 + x2;  
    }

    var a="53669988.000";
    alert(format_number(a));
    alert(format_number("wahh"));
    alert(format_number(0));
    alert(format_number(6698.0023));

c#及js实现将金融变成3位一逗号

标签:

原文地址:http://www.cnblogs.com/taoshengyujiu/p/5779409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!