首页 > Web客户端技术 > parseInt bug in firefox 3.5.2

parseInt bug in firefox 3.5.2

2009年9月6日


来,先让我们看下面的JS代码:

  for(var i=0;i < 1000;i++)
  {
        var result = parseInt(-15.02);
	document.write( result );
	document.write( '' );
  }

你觉得他会输出什么?一串的-15?恩,也许在其他浏览器中是这样的,但是据我的测试,在Firefox 3.5.2里面,只有开始的几个是-15,其他都是-16,而且-15的个数不一定,有时是3个,有时又会出现4个。

那么,怎么解决呢,将其改为:

parseInt(-15.02,10);

即可


English version for foreign friends:

Ok,let’s get to the codes below:

  for(var i=0;i < 1000;i++)
  {
        var result = parseInt(-15.02);
	document.write( result );
	document.write( '' );
  }

What do you think it will output?Rows of -15?It might be in other browsers except Firefox 3.5.2 according to my test.In Firefox 3.5.2,only the begins are -15,others are -16,and the number of -15 is varying at different time,sometime 3 and sometimes maybe 4.

Then,codes following will works:

parseInt(-15.02,10);

随机内容

hanguofeng Web客户端技术

  1. dra
    2009年9月7日02:09 | #1

    传说中的双语么?

  2. 2009年11月3日17:30 | #2

    大师,我决定以后常来你家踹门了,欢迎我哦。淘一下你这里的技术文章。

  3. 4xuxiudong@sohu.com
    2010年1月30日23:34 | #3

    韩工,您好!
    今天刚买了您的一本书,关于ASP的,还在拜读中!
    博客上怎么没再提关于ASP的文章呢?

  1. 目前还没有任何 trackbacks 和 pingbacks.