Created
April 8, 2017 19:30
-
-
Save DavidMetcalfe/81ab19f2a579f5d6de493998e221b32d to your computer and use it in GitHub Desktop.
AutoHotkey function to perform penny rounding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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