Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total-calc-error #20

Open
harshil-kakdiya opened this issue Feb 9, 2024 · 1 comment
Open

Total-calc-error #20

harshil-kakdiya opened this issue Feb 9, 2024 · 1 comment

Comments

@harshil-kakdiya
Copy link

in the InvoiceForm.js handleCalculationTotal() is not calculate total for 2or more items.

@evgenii-komornyi
Copy link

try this instead:
handleCalculateTotal() {
const { items, taxRate, discountRate } = this.state;

let subTotal = items.reduce((acc, item) => {
return acc + parseFloat(item.price) * parseInt(item.quantity);
}, 0);

// Ensure subTotal is a floating point number with two decimal places
subTotal = parseFloat(subTotal.toFixed(2));

const taxAmmount = parseFloat((subTotal * (taxRate / 100)).toFixed(2));
const discountAmmount = parseFloat((subTotal * (discountRate / 100)).toFixed(2));
const total = parseFloat((subTotal - discountAmmount + taxAmmount).toFixed(2));

this.setState({
subTotal,
taxAmmount,
discountAmmount,
total
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants