Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

js math方法

作者:此岸蝶恋花   发布日期:2026-04-27   浏览:70

// Math.abs() 方法返回一个数的绝对值
console.log(Math.abs(-4.7)); // 输出: 4.7

// Math.round() 方法四舍五入为最接近的整数
console.log(Math.round(4.4)); // 输出: 4
console.log(Math.round(4.5)); // 输出: 5

// Math.ceil() 方法向上取整
console.log(Math.ceil(4.1)); // 输出: 5

// Math.floor() 方法向下取整
console.log(Math.floor(4.9)); // 输出: 4

// Math.max() 方法返回一组数中的最大值
console.log(Math.max(1, 3, 5, 7)); // 输出: 7

// Math.min() 方法返回一组数中的最小值
console.log(Math.min(1, 3, 5, 7)); // 输出: 1

// Math.random() 方法返回介于 0 和 1 之间的伪随机数
console.log(Math.random()); // 输出: 例如 0.89723456789

// Math.pow() 方法返回 x 的 y 次幂
console.log(Math.pow(2, 3)); // 输出: 8

// Math.sqrt() 方法返回一个数的平方根
console.log(Math.sqrt(16)); // 输出: 4

// Math.PI 属性返回圆周率 π (约等于 3.14159)
console.log(Math.PI); // 输出: 3.141592653589793

以上代码展示了 JavaScript 中 Math 对象的一些常用方法和属性。每个方法都有相应的解释说明,帮助你理解其功能。

上一篇:js math 取整

下一篇:js math函数

大家都在看

js 数组打乱顺序

js 两个数组取交集

js 数组对象排序

js 对象数组排序

js 数组删掉第一个值

js fill

js fill方法

js 数组连接

js json数组

js 数组复制

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站