function toThousands(num) {
  var num = (num || 0).toString(),
    result = '';
//判断是否带小数点
  if (num.split('.')[1]) {
    var numInt = num.split('.')[0],
    numFlo = num.split('.')[1];
    result = formatter(numInt) + '.' + numFlo
  } else {
    result = formatter(num);
  }
  return result;

//格式化整数

  function formatter(numInt) {
    var resultInt = '';
    while (numInt.length > 3) {
      resultInt = ',' + numInt.slice(-3) + resultInt;
      numInt = numInt.slice(0, numInt.length - 3);
    }
    if (numInt) {
      resultInt = numInt + resultInt;
    }    
    return resultInt;
  }
}
05-11 05:05