javascript把number转化成百分比

(Math.round(this * 10000)/100).toFixed(0) + '%';

$scope.meterInputChange=function (diary) {
    var percent=/^\d{1,3}%$/.test(diary.meter);     //百分数
    var decimal=/^[0]\.\d{1,}$/.test(diary.meter);  //小数

    if(percent) $scope.updateMeter(diary);
    else if(decimal) numToPercent(diary);
    else if(diary.meter=="1") numToPercent(diary);
    else alert("处理进度只能输入百分数、小数,请重新输入!")
};

//数字转换为百分数
var numToPercent=function (diary) {
    diary.meter=(Math.round(diary.meter * 10000)/100).toFixed(0) + '%';
    $scope.updateMeter(diary);
};

posted on 2017-10-20 18:18  Yoooshiki  阅读(2046)  评论(0编辑  收藏  举报

导航