JavaScript Math cos()方法

下面是一个例子 数学cos() 方法

null
  • 例子:

html

< script type="text/javascript">
document.write("The cos of 0 : " + Math.cos(0));
</ script >


  • 输出:
The cos of 0 : 1

这个 数学cos() 方法用于返回数字的余弦。数学。cos()方法返回一个介于-1和1之间的数值,表示以弧度为单位的角度的余弦。cos()是一种静态数学方法,因此,它总是用作数学。cos(),而不是创建数学对象的方法。 语法:

Math.cos(value)

参数: 此函数接受上述单个参数,如下所述:

  • 价值: 此参数是以弧度为单位的数字。

返回: 这个 数学cos() 函数返回给定数字的余弦,其范围为-1到1。 下面的示例演示了JavaScript中的cos()方法:

  • 例1:
Input: Math.cos(010)Output : -0.14550003380861354
  • 例2:
Input: Math.cos(10)Output : -0.8390715290764524

以上方法的更多代码如下: 项目1: 当1作为参数传递时。

html

< script type="text/javascript">
document.write("Result : " + Math.cos(1));
</ script >


输出:

Result : 0.5403023058681398

项目2: 当PI作为参数传递时。

html

< script type="text/javascript">
document.write("Result : " + Math.cos(Math.PI));
</ script >


输出:

Result : -1

支持的浏览器:

  • 谷歌Chrome 1及以上版本
  • Internet Explorer 3及以上版本
  • Firefox 1及以上版本
  • 歌剧3及以上
  • Safari 1及以上
© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享