简体   繁体   中英

With Javascript, enforce using scientific notation to represent numbers in IE8

I found that when using IE8, the large number will NOT be represented in scientific notation (eg, 5e25), but it will be with Firefox3.

Can I enfore using scientific notation representation for large number with IE8?

Thanks.

AFAIK, the toExponential method is supported in all modern browsers. The basic form is:

number = 12345678;
x = number.toExponential(7);
alert(x);

This should produce 1.2345678e+7.

//You can roll your own if you only care about large numbers-

Number.prototype.minExponent=function(min){
  min= min|| 5.0e+10;// define your own large number
  if(this>min)return this.toExponential();
  return this;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM