Last active
August 18, 2023 03:41
-
-
Save petrosmm/621e2cefb21e22f6a04122235ec5960a to your computer and use it in GitHub Desktop.
A function to assist in MidpointRounding.AwayFromZero on the client side
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
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