JS小数位数不足二位,自动补零0

时间:2021-07-29 15:55:14   收藏:0   阅读:23
function returnFloat(value){
  var value = Math.round(parseFloat(value) * 100) / 100;
  var s = value.toString().split(".");
  if(s.length== 1){
    value = value.toString() + ".00";
    return value;
  }
  if (s.length > 1) {
    if (s[1].length < 2) {
      value = value.toString() + "0";
    }
    return value;
  }
}

原文:https://www.cnblogs.com/tsxx/p/15074599.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!