文章目录
大数相加
按位相加
var a="9007199254740991";
var b="1234567899999999999";
function plusNum(num1,num2){
var length=Math.max(num1.length,num2.length);
num1=num1.padStart(length,0);
num2=num2.padStart(length,0);
var all=0;
var go=0;
var sum="";
for(var i=length-1;i>=0;i--){
all=parseInt(num1[i])+parseInt(num2[i])+go;
go=Math.floor(all/10);
sum=all%10+sum;
}
return sum
}
console.log(plusNum(a,b));