ITeye博客

js实现小数转百分比

deejay · 2011-12-26 15:05 · javascript · Web前端 · Markdown

Number.prototype.toPercent = function(n){n = n || 0;return ( Math.round( this * Math.pow( 10, n + 2 ) ) / Math.pow( 10, n ) ).toFixed( n ) + '%';}
var A=0.358975, B=0.25554;
 alert([A, A.toPercent(3), B, B.toPercent()].join('\n'));

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。