Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

midpointrounding.awayfromzero javascript

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;
}
 
PREVIOUS NEXT
Tagged: #javascript
ADD COMMENT
Topic
Name
2+2 =