Using JavaScript to add two large numbers

Source: Internet
Author: User
Tags tostring
(function () {var addlarge = function (n1,n2) {var over = 0;  
      
      
var ret = "";  
var len = math.min (n1.length,n2.length);  
var sln1 = n1.substr (n1.length-len,n1.length);  
      
var sln2 = n2.substr (n2.length-len,n2.length);  
for (var i = len;i > 0; i--) {var di = parseint (sln1[i-1]);  
      
var dj = parseint (Sln2[i-1]); RET = (over + di + dj) >= 10?  
      
(Over + di + DJ)-+ ret): ((OVER+DI+DJ) + ret); over = ((over + di + DJ)/10) |  
      
0; } if (N1.length!= n2.length) {if (N1.length > n2.length) {ret = Addlarge (N1.SUBSTR (  
0,n1.length-len), over.tostring () + ret;  
else{ret = Addlarge (N2.substr (0,n2.length-len), over.tostring ()) + ret;  
return ret;  
      
else{if (over > 0) ret = over + ret;  
return ret;  
      
}  
      
      
};  
var L1 = "9999999999999";  
var L2 = "1111111111111";  
var r = addlarge (L1,L2);  
      Console.log (R);
      
      
})(); 

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.