Home >Web Front-end >JS Tutorial >How to find the circumference of a circle in javascript

How to find the circumference of a circle in javascript

青灯夜游
青灯夜游Original
2022-01-18 16:14:384319browse

In JavaScript, you can use the PI attribute of the Math object to find the circumference of a circle. This attribute can return the ratio of the circumference of a circle to its diameter (ie, pi); the syntax for finding the circumference of a circle is " Math.PI*2*radius of circle”.

How to find the circumference of a circle in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In javascript, you can use the PI attribute of the Math object to find the circumference of the circle.

PI attribute is π, which is the ratio of the circumference of a circle to its diameter, that is, pi. This value is approximately 3.14.

Example:

It is known that the radius of a circle is 2, what is the circumference of the circle?

Calculation code:

var r=2;
var circumference=Math.PI*2*r;
console.log("半径为2的圆的周长为:"+circumference);

How to find the circumference of a circle in javascript

[Related recommendations: javascript learning tutorial]

The above is the detailed content of How to find the circumference of a circle in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn