Skip to content

Instantly share code, notes, and snippets.

@DavidMetcalfe
Created April 8, 2017 19:30
Show Gist options
  • Save DavidMetcalfe/81ab19f2a579f5d6de493998e221b32d to your computer and use it in GitHub Desktop.
Save DavidMetcalfe/81ab19f2a579f5d6de493998e221b32d to your computer and use it in GitHub Desktop.
AutoHotkey function to perform penny rounding
pennyRound(val)
{
;Performs penny rounding on inputted float, and
;returns calculated amount.
sub := SubStr(val, 0, 1)
subMult := round((sub * 0.01), 2)
if (subMult <= 0.02) {
price := round((val - subMult), 2)
return price
}
else if (subMult > 0.02 && subMult < 0.05) {
price := round(round(val, 1) + 0.05, 2)
;price := round((val + subMult), 2)
return price
}
else if (subMult > 0.05 && subMult < 0.07) {
price := floor(val*10)/10
price := round(price + 0.05, 2)
return price
}
else if (subMult > 0.07) {
price := ceil(val*10)/10
price := round(price, 2)
return price
}
else {
return val
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment