Math.round()和ToFixed()

Math.round(1.6)=2 

Math.round(-1.4)=-1 

var k = 1.74.toFixed(1), m = 1.75.toFixed(1), n = 1.76.toFixed(1),i=-1.49.ToFixed(1);   结果 1.7,1.8,1.8,-1.5

当为负数时round得到的结果可能不是我们想要的所以需要添加绝对值

num Math.floor Math.round Math.ceil
1.4 1 1 2
1.5 1 2 2
1.6 1 2 2
-1.4 -2 -1 -1
-1.5 -2 -1 -1
-1.6 -2 -2 -1

substring(start,end)和substr(start,total)

var s1 = new String("010-9898999");

alert(s1.substring(1,4)); //10-

alert(s1.substr(1,4));//10-9

相关文章:

  • 2022-12-23
  • 2021-12-04
  • 2021-10-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-12-08
  • 2021-12-24
猜你喜欢
  • 2021-07-27
  • 2021-10-23
  • 2021-04-25
  • 2021-07-31
  • 2021-11-19
  • 2022-02-09
  • 2021-12-05
相关资源
相似解决方案