Skip to content

Instantly share code, notes, and snippets.

@wehrhaus
Created July 8, 2014 16:05
Show Gist options
  • Save wehrhaus/16ded9bc5a67066fd3f8 to your computer and use it in GitHub Desktop.
Save wehrhaus/16ded9bc5a67066fd3f8 to your computer and use it in GitHub Desktop.
Stylus Percentage Difference Calcualator
// http://www.mathsisfun.com/percentage-difference.html
// get percentage difference of 2 numbers
// returns optional unitType as well in the form of '%, px, em' etc
getPercentageDifference(v1, v2, unitType = '')
return unit(((v1 - v2) / ((v1 + v2) / 2)) * 100, unitType)
// get percentage difference of 2 numbers then returns the result minus a given max value
// returns optional unitType as well in the form of '%, px, em' etc
getPercentageDifferenceMinusMax(v1, v2, max, unitType = '')
return unit(max - getPercentageDifference(v1, v2), unitType)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment