JavaScript 的 Math 对象中的 cos 方法返回一个数字的余弦值。
Math.cos 方法返回一个数字的余弦值。
Math.cos(x);
参数 | 描述 |
---|---|
x | 必需。必须是一个数值。 |
类型 | 描述 |
---|---|
Number | x 的余弦值。返回的是 -1.0 到 1.0 之间的数。 |
该函数只支持 JavaScript 1.0 即以上版本。
该函数支持所有的主流浏览器。
使用 Math.cos 方法求余弦值
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Math.cos求余弦值</title>
<script type="text/javascript">
console.log("嗨客网(www.haicoder.net)");
console.log("cos 0.2 =", Math.cos(0.2));
console.log("cos 1 =", Math.cos(1));
console.log("cos -1 =", Math.cos(-1));
console.log("cos Math.PI =", Math.cos(Math.PI));
</script>
</head>
</html>
程序运行后,控制台输出如下:
我们使用 Math.cos 方法获取了参数的余弦值。
JavaScript 的 Math 对象中的 cos 方法返回一个数字的余弦值。JavaScript cos 方法语法:
Math.cos(x);