JQuery Number Formatting

前端 未结 8 827
鱼传尺愫
鱼传尺愫 2020-11-27 15:43

There are way too many questions and answers about this basic functionality, I cannot see the wood for the trees.

In Java there is only one simple answer (jav

相关标签:
8条回答
  • 2020-11-27 16:26

    Putting this http://www.mredkj.com/javascript/numberFormat.html and $('.number').formatNumber(); concept together, you may use the following line of code;

    e.g. <td class="number">1172907.50</td> will be formatted like <td class="number">1,172,907.50</td>

    $('.number').text(function () { 
        var str = $(this).html() + ''; 
        x = str.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'); 
        } 
        $(this).html(x1 + x2); 
    });
    
    0 讨论(0)
  • 2020-11-27 16:29

    If you need to handle multiple currencies, various number formats etc. I can recommend autoNumeric. Works a treat. Have been using it successfully for several years now.

    0 讨论(0)
提交回复
热议问题