我有一个 jQuery 插件进度表,它可以动画并有一个回调函数,我可以在该函数中将文本值设置为动画,直到达到仪表值。
https://github.com/kottenator/jquery-circle-progress
回调值的格式为 0.12798798 等,我将其格式化为 12%。
我的问题是,如果值为 100%,我的代码将返回 00%
$('#circle').circleProgress({
startAngle: 90,
size: 240,
thickness: 22,
fill: { gradient: [['#0681c4', .5], ['#4ac5f8', .5]], gradientAngle: Math.PI / 4 }
}).on('circle-animation-progress', function(event, progress, stepValue) {
$(this).find('strong').text(String(stepValue.toFixed(2)).substr(2)+'%');
});
我确信有更好的方法。
最佳答案
可以简化如下:
(stepValue*100).toFixed(0) + '%'
关于javascript 格式数字 2 位然后 3 为 100%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30900211/