JQuery显示太多小数

时间:2013-06-20 23:45:10

标签: jquery jquery-ui-progressbar

我有一个进度条的代码,但.progress-label显示的小数太多,类似于(2.020302032400%)。

我的代码看起来像这样

<script>     
 $(document).ready(function() {
 $("#progressbar").progressbar({
         value: 1 
     });
 $("#progressbar > .ui-progressbar-value").animate({
         width: "37%"            
     }, {
       step: function(width){
         $('.progress-label').text(width + '%'); }
       }, 2000);

 });

 </script>

我怎样才能摆脱小数??是否可以让百分比增加一个?,现在它的速度太快了。

----------------------------------- EDIT ----------- ------------------------

通过Barmar回答我完成了代码,如果有人需要解决方案,那么它是:

$(document).ready(function() {
$("#progressbar").progressbar({
         value: 1 
  });
$("#progressbar > .ui-progressbar-value").animate({
         width: "37%"            
}, {
duration: 10000,
step: function (width){
    $('.progress-label').text(width.toFixed(0) + "%");
      }
});
});

1 个答案:

答案 0 :(得分:1)

使用toFixed()方法指定小数位数。

$('.progress-label').text(width.toFixed(1) + '%'); }

将在小数点后显示1位数。

相关问题