美文网首页随笔-生活工作点滴
2019-07-04 js大整数相加

2019-07-04 js大整数相加

作者: DreamNeverDie | 来源:发表于2019-07-04 19:51 被阅读0次
function sumBigNumber(a, b) {
  var res = '',
    temp = 0;
    a = a.toString().split('');
    b = b.toString().split('');
  while (a.length || b.length || temp) {
    temp += ~~a.pop() + ~~b.pop();
    res = (temp % 10) + res;
    temp = temp > 9;
  }
  return res.replace(/^0+/, '');
}

相关文章

网友评论

    本文标题:2019-07-04 js大整数相加

    本文链接:https://www.haomeiwen.com/subject/iikdhctx.html