openexchangerates / accounting.js

A lightweight JavaScript library for number, money and currency formatting - fully localisable, zero dependencies.
http://openexchangerates.github.io/accounting.js
MIT License
4.95k stars 528 forks source link

Large numbers formatted incorrectly in IE8 #68

Open mckramer opened 10 years ago

mckramer commented 10 years ago
var number = accounting.formatNumber(10000000000000000000000000000000000000/184.77, 2);
// (IE8)   number = "5,.406,574,394,463,668,5e+34.00"
// (Other) number = "5.4065743944636685e+34"

In formatNumber, the base resolves to "5.4065743944636685e+34" and the decimal resolves to "00".

This is due to Number.prototype.toFixed returning "54065743944636685000000000000000000.00", which then the base pulls out the full integer before returning it as scientific notation. I was under the impression that all of the browser implementations of toFixed properly displayed scientific notation when > 1e21.

Number.prototype.toString is properly returning "5.406574394463668e+34".

Is this simply a known issue/limitation of IE8? Or is there a workaround?