Home > Article > Web Front-end > How to find the circumference of a circle in javascript
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”.
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);
[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!