Run this snippet
document.write(parseFloat("999999999999999"));
document.write("<br>");
document.write(parseFloat("555555555555555555555555.99"));
document.write("<br>");
document.write(parseInt("9999999999999999.99"));
document.write("<br>");
document.write(parseInt("88888888888888888",10));
document.write("<br>");
document.write(parseFloat("88888888888888888"));
You will notice that the conversion from string to a valid number is buggy. This is a known limitation in javascript up to 15 digits(?). I know that if it is a JS limitation then we can't do anything about it. But in the ajax enterprise world, we will always need to compute lots in the browser. And with the advent of node.js in the server-side, this is no longer tolerable and the community need to find a solution to circumvent, if not solve, this problem once and for all.
My boss found a high precision Javascript calculator but it is cpu hogging. Another solution is to give that to the server-side but that will increase "chattiness" which is an anti-pattern. What I am asking is, how would you solve this?
Please correct me If I am wrong in any of the things I stated above.
If JavaScript can't parse huge numbers, chances are it won't be able to do anything useful with them either, like calculations (without the memory-intensive calculator you posted a link to). If you need to display the number, why not use an Ajax request? Just try to consolidate multiple number-to-string operations into a single request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With