保留整数的方法

 function checkNumber5 (inputValue, numbers){
  if (inputValue.indexOf(".") == -1) {
    if (inputValue.length > numbers) {
      inputValue = inputValue.substr(0, numbers);
    }
  } else {
    var arr = inputValue.split(".");
    var length = arr[0].length;
    if (length > numbers) {
      var totalInt = arr[0];
      var totalDecimal = 0;
      if (arr[1].length > 0) {
        totalDecimal = arr[1] * Math.pow(10, arr[1].length) / Math.pow(10, arr[1].length) / Math.pow(10, arr[1].length);
      }
      var bigDecimal = parseInt(totalInt.substr(0, numbers)) + totalDecimal;
      inputValue = bigDecimal;
    }
  }
  return inputValue;
}
posted @ 2021-06-24 15:40  未几  阅读(393)  评论(0编辑  收藏  举报