js 数字

1、取数字数组中最大和最小值

var numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411];
var maxInNumbers = Math.max.apply(Math, numbers);
var minInNumbers = Math.min.apply(Math, numbers);
console.info(maxInNumbers+"#"+minInNumbers);

控制台输出:

2.null,undefined替换取代三位运算符更简单:

var tt = undefined;
var i = tt||100;
console.log(i)

控制台输出:

3.保留小数点

var num =2.443242342;
num = num.toFixed(4);
console.log(num)

控制台输出:

 

posted on 2017-09-01 17:11  ckx0709  阅读(233)  评论(0编辑  收藏  举报

导航