Get the App
SLTechnology News&Howtos  ›  Development  › 

How to calculate the Circle area by javascript

Shulou Source: shulou.com Published: 2022-06-02 07:36:59 09月28日 Update

Editor to share with you how to achieve javascript circle area, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

In JavaScript, the code for finding the area of a circle is "Math.PI * Math.pow (radius, 2)"; "Math.PI" is used to obtain the value of pi, and the pow () method of the Math object is used to obtain the square of the radius, and the area of the circle is obtained by multiplying the two numbers.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

You can use the Math object in JavaScript to perform mathematical operations, and the Math object is used to perform mathematical tasks.

The Math object is not a class of objects like Date and String, so there is no constructor Math ().

For example:

Var x = Math.PI; / / returns PIvar y = Math.sqrt (16); / / returns the square root of 16

There is also the pow () method

The syntax is:

Math.pow (XBI y)

The pow () method returns the y power of x.

Let's take a look at how to calculate the primary color area and perimeter based on an example, as follows:

Document / / rounding function round (number, X) {X = (! X? 2: X); return Math.round (number*Math.pow (10Magine X)) / Math.pow (10Magazine X);} var r = Number (prompt ('Please enter the radius of the circle')) If (! isNaN (r)) {var m = round (Math.PI * Math.pow (r, 2), 2); alert ('area =' + m);} else {alert ('Please enter a number!');}

Output result:

The above is all the contents of the article "how to achieve Circle area in javascript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Area object radius method article content mathematics examples input rounding not much two code task function primary color perimeter circumference pi most Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information OPPO Reno Xiaomi Shulou Technology