Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to calculate the Circle area by javascript

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report