SarthakKeshari / calc_for_everything

This repository aims to provide Calculators for educational, professional, scientific, health and well-being and other purposes.
https://calc-for-everything-psi.vercel.app
MIT License
114 stars 104 forks source link

Margin calc #640

Closed wuhue closed 1 year ago

wuhue commented 1 year ago

Issue Id you have worked upon -

Margin Calculator

Briefly explain your program logic -

The component uses the useState hook to define the following state variables: cost and revenue store the user-inputted product cost and selling price or revenue. markupPercentage and grossMarginPercentage store the calculated markup percentage and gross margin percentage. The calculateMargin function is defined. This function tries to parse cost and revenue as floats, then calculates the profit (profitFloat), markup percentage (markupPercentageFloat), and gross margin percentage (grossMarginPercentageFloat) based on the formulae provided. The calculated percentages are then stored in the corresponding state variables using setMarkupPercentage and setGrossMarginPercentage.

In the rendering part, Material-UI components are used to create the user interface: TextField components are used for inputting the product cost and selling price/revenue. The onChange event listeners update the corresponding state variables (setCost and setRevenue). Clicking the "Calculate Margin" button triggers the calculateMargin function, which calculates and updates the markup percentage and gross margin percentage state variables. The calculated percentages are displayed using the Typography component.

Screenshots(Attach 2 screenshots of your own input and output) -

image image


By raising this PR I affirm that -