I have a function to round a number given to the function to the nearest whole pence.
<script type='text/javascript'>
Math.roundNumber = function(a,b){
if(!isNaN(parseInt(a))){
c = Math.pow(10,b);
return (Math.round(a*c)/c);
}
return false;
}
</script>
however it has come to my attention that the said number inputted into the function must only be rounded up to the nearest one pence however it must be rounded to two decimal places.
E.G.
15.236562213541684 would = 15.24 9846.65456169846 would = 9846.66
I thought it would just be a case of changing return (Math.round(a*c)/c); To return (Math.ceil(a*c)/c);
Obviously I was very wrong.
Any help on this matter?
** EDIT **
Here is the formula that I'm trying to achieve maybe it'll help
a = intrest price
b = terms
c = a/b
d = c*(b-1)
e = a-d
so for example
a = 295.30
b = 156
c = 295.30/156 = 1.90 (rounded up to nearest decimal as above)
d = 1.90 * (b-1) = 294.50
e = 295.30 - 294.50 = 0.80
can anyone right a function to do the above?
Here is a link to the current code i have including the formula... its a very old formula that I made when I first started JavaScript (which is a while ago now) however I'm still no better now as I was back then.
Can anyone clean it up to see if they can see why its not working to match the function above?