Skip to content

Instantly share code, notes, and snippets.

@dashawk
Last active October 20, 2017 08:03
Show Gist options
  • Save dashawk/d503302bb17e5769add97fe5fd59ea02 to your computer and use it in GitHub Desktop.
Save dashawk/d503302bb17e5769add97fe5fd59ea02 to your computer and use it in GitHub Desktop.
//region Get the Margin
var cost = 5;
var sell = 10;
var margin = 0;
// Original Formula
margin = ((sell - cost) / sell) * 100;
console.log('[Original]Margin', margin);
// Shorthand Formula
margin = (1 - (cost / sell)) * 100;
console.log('[Shorthand]Margin', margin);
//endregion
//region Get the Sell
var cost = 5;
var sell = 0;
var margin = 50; // 50%
// Original Formula
sell = cost / (1 - (margin / 100));
console.log('[Original]Sell', sell);
//endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment