midpointrounding awayfromzero javascript

Solutions on MaxInterview for midpointrounding awayfromzero javascript by the best coders in the world

showing results for - "midpointrounding awayfromzero javascript"
Pablo
26 Mar 2019
1function RoundAwayFromZero(startValue, digits) {
2var decimalValue = 0;
3digits = digits || 0;
4startValue *=  parseFloat(Math.pow(10, (digits + 1)));
5decimalValue = parseInt(Math.floor(startValue)) - (Math.floor(startValue / 10) * 10);
6startValue = Math.floor(startValue / 10);
7if (decimalValue >= 5) {
8    startValue += 1;
9}
10startValue /=  parseFloat(Math.pow(10, (digits)));
11return startValue;
12}