728x90

✨ PI(파이)를 이용한 계산이 필요할 때 사용할 수 있는 helper method

💻Example Code

const radius = 2
const areaOfCircle = radius * radius * Math.PI;

console.log( areaOfCircle );
console.log( Math.PI );

실행 결과

🧨 원의 넓이를 구하는 공식: 반지름*반지름*PI(파이)

😋 소수점 아래를 조정하고 싶다면 toFixed()를 사용해주면 된다. 링크 참고(https://dpsc615.tistory.com/14)

👉 자세한 내용은 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/PI

 

Math.PI

The Math.PI property represents the ratio of the circumference of a circle to its diameter, approximately 3.14159:

developer.mozilla.org

 

'JavaScript > Built-in Method etc.' 카테고리의 다른 글

Math.round()  (0) 2020.02.16
Math.abs()  (0) 2020.01.28
Array.prototype.forEach()  (0) 2020.01.23
Math.pow()  (0) 2020.01.22
Math.random()  (0) 2020.01.18

+ Recent posts