Note that there are some explanatory texts on larger screens.

plurals
  1. POrounding in base 10
    primarykey
    data
    text
    <p>I have a function to round a number given to the function to the nearest whole pence.</p> <pre><code>&lt;script type='text/javascript'&gt; Math.roundNumber = function(a,b){ if(!isNaN(parseInt(a))){ c = Math.pow(10,b); return (Math.round(a*c)/c); } return false; } &lt;/script&gt; </code></pre> <p>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.</p> <p>E.G.</p> <pre> 15.236562213541684 would = 15.24 9846.65456169846 would = 9846.66 </pre> <p>I thought it would just be a case of changing return (Math.round(a<em>c)/c); To return (Math.ceil(a</em>c)/c);</p> <p>Obviously I was very wrong.</p> <p>Any help on this matter?</p> <p>** EDIT ** </p> <p>Here is the formula that I'm trying to achieve maybe it'll help</p> <pre><code>a = intrest price b = terms c = a/b d = c*(b-1) e = a-d </code></pre> <p>so for example </p> <pre><code>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 </code></pre> <p>can anyone right a function to do the above? </p> <p><a href="http://pastie.org/638476" rel="nofollow noreferrer">Here</a> 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.</p> <p>Can anyone clean it up to see if they can see why its not working to match the function above?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload