How to use Arithmetic Operations In Javascript
In this approach, we are using the formula for the circumference of a circle, which is given by 2πr, where r is the radius. By assigning the radius r=2 and performing the arithmetic operations, we calculate the circumference and display the result with three decimal places using toFixed(3).
Syntax:
let res = 2 * 3.1416 * r;
Example: The below example uses Arithmetic Operations to find the Circumference of a Circle in JavaScript.
let r = 2;
let res = 2 * 3.1416 * r;
console.log(`${res.toFixed(3)}`);
Output
12.566
Find Circumference of a Circle using JavaScript
The Circumference of the Circle is: 2*pi*r. We can calculate this value in JavaScript using various approaches that are implemented below with examples and output.
These are the following approaches:
Table of Content
- Using Arithmetic Operations
- Using Math.PI
- Using Math.PI and Math.pow