Skip to content

Instantly share code, notes, and snippets.

@petrosmm
Last active August 18, 2023 03:41
Show Gist options
  • Save petrosmm/621e2cefb21e22f6a04122235ec5960a to your computer and use it in GitHub Desktop.
Save petrosmm/621e2cefb21e22f6a04122235ec5960a to your computer and use it in GitHub Desktop.
A function to assist in MidpointRounding.AwayFromZero on the client side
function RoundAwayFromZero(startValue, digits) {
var decimalValue = 0;
digits = digits || 0;
startValue *= parseFloat(Math.pow(10, (digits + 1)));
decimalValue = parseInt(Math.floor(startValue)) - (Math.floor(startValue / 10) * 10);
startValue = Math.floor(startValue / 10);
if (decimalValue >= 5) {
startValue += 1;
}
startValue /= parseFloat(Math.pow(10, (digits)));
return startValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment