1. ## Rounding ...

Guys,

This problem has been bugging me for a couple days now ... I hope someone can help me.

I have to round a fractional value from a form input to either 0, 25, 50 or 75. I have succesfully tested the value and stripped the decimal place. If the value is for example .1, I round it to 0. If the value is say .2, I round it to .25. My problem is that when the value is > .75, my function is returning undefined. For the sake of brevity I will include only the relevant code.

Code:
```var increments = new Array(0,25,50,75);

CharBefore = parseFloat(CharBefore); //the whole number
CharAfter = parseFloat(CharAfter);   //the decimal

var x = parseFloat(increments.length - 1) ;

for ( i = 0; i <=  x ; i++  ) {

var testValue = parseFloat(increments[i]);
if (CharAfter > testValue) { continue ; }
else {
var lowerValue = parseFloat(increments[i-1]);
if ((CharAfter > testValue) && (i==x)) {

median =  (testValue + 100)/2 ;
if (CharAfter >= median) {
CharAfter = '0';
CharBefore++;} //round up to next whole number
else { CharAfter = testValue; }

}
else {
median =  (testValue + lowerValue)/2 ;
if (CharAfter >= median) { CharAfter = testValue; }
else { CharAfter = lowerValue; }

}
return  CharBefore + '.' + CharAfter;
break;

}

} // End for loop```
Any help is greatly appreciated.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•