Skip to content

Instantly share code, notes, and snippets.

@brunurd
Last active July 22, 2025 19:57
Show Gist options
  • Save brunurd/362117ada53f3fd297bf10d0a604c10b to your computer and use it in GitHub Desktop.
Save brunurd/362117ada53f3fd297bf10d0a604c10b to your computer and use it in GitHub Desktop.
Function to calculate how much gross do you need to reach a net target.
/**
* calculateInvoice is a function to calculate how much gross do you need to reach a net target.
*
* @param netTarget The net you want to receive.
* @param taxPercent The tax percentage normally practiced for company segment and government.
* @returns Object which includes the: tax, net and gross results.
*/
function calculateInvoice(netTarget, taxPercent) {
for (let gross = netTarget; gross < (netTarget*1000); gross++) {
const tax = (gross*taxPercent)/100;
const net = gross-tax;
if (net >= netTarget) {
return { netTarget, tax, net, gross };
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment