Open In App

Percentage calculator using HTML CSS and JavaScript

Last Updated : 18 Apr, 2025
Comments
Improve
Suggest changes
7 Likes
Like
Report

The percentage calculator is useful for students, shopkeepers, and for solving basic mathematical problems related to percentages. In this article, we are going to learn, how to make a percentage calculator using HTML CSS, and JavaScript

Formula used:

  • What is X percent of Y is given by the formula: X percent of Y =(X/100)* Y
  • X is what percent of Y is given by the formula: X is what percent of Y= (X/Y)×100%, where X, Y > 0

Approach

  1. Input Retrieval:
    • Use document.getElementById("elementId").value to get input values.
  2. Calculation and Formatting:
    • percentage_1: Calculate the percentage and set the result in an element.
    • percentage_2: Calculate the percentage, append "%", and set the formatted result in an element.
  3. DOM Manipulation:
    • Use document.getElementById("elementId").value to set results in HTML elements.
  4. Mathematical Operations:
    • Perform basic operations (multiply, divide, add) for percentage calculations.

Example: This example shows the implementation of the above approach.

HTML
CSS JavaScript

Output


Next Article

Similar Reads