前端开发之JS(数值)

Math.abs()

绝对值

Math.round()

四舍五入变整型

Math.ceil()向上取整

Math.ceil(1.1) ;//2

Math.floor()向下取整

Math.floor(1.1);//1

Math.max()

求最大值

Math.min()

求最小值

Math.random()

左闭右开 0~1


parseInt(string)

parseInt('1.1');  //1
parseInt('1b2.4');  //1
parseInt('w');  //NaN

只能识别数字

parseFloat(string)

parseFloat('100.1'); //100.1
parseFloat('12.4b5'); //12.4
parseInt('w');  //NaN

Number(value)

Number('100.1');//100.1
Number('12.4b5')//NaN

num.toFixed(digits)

(100.123).toFixed(2); //"100.12"
(100.123).toFixed(0); //"100"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容