开发者

Javascript showing in dollars

How would I display JavaScript output numbers in dollar format? I.E. $20.00 then $2,000.00 when the number gets larger. Ok so sample code.

if(this.getField("Account Name RequiredRow1").value !="") {
    event.value = 20;
}
else{
    event.开发者_C百科value = "";
}


function formatCurrency(num) {
    num = isNaN(num) || num === '' || num === null ? 0.00 : num;
    return '$' + parseFloat(num).toFixed(2);
}

This is the easiest way


Here's the function that I use.. Basically the same as @Senad's except it adds commas:

function(val) {
    var valString = val.toFixed(2).toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ",");
    return "$" + valString;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜