Javascript parseFloat '1.23e-7' gives 1.23e-7 when need 0.000000123

前端 未结 3 1609
梦谈多话
梦谈多话 2021-01-04 19:01
parseFloat(1.51e-6);
// returns 0.00000151

parseFloat(1.23e-7);
// returns 1.23e-7
// required 0.000000123

I am sorting table columns containing a

3条回答
  •  旧巷少年郎
    2021-01-04 19:22

    the problem is not parseFloat, but sort that uses string comparison by default. Try enforcing numeric comparison:

    a.sort(function(x, y) { return x - y })
    

提交回复
热议问题