Better way of rounding off or rounding up in javascript
<p>I have this problem with rounding up or rounding off with javascript. Well it gets the job done but there are some scenarios that it fails to do the job properly.</p>

<p>For example.</p>

<p>The price is 0.30 with a 15% discount should have 0.255 or 0.26 as result. (this is somehow okay)</p>

<p>The price is 79.99 with a 50% discount should have 40 as result. (actual result is 39.995)</p>

<p>Tried using this as reference <a href="http://stackoverflow.com/questions/2861055/using-tofixed2-and-math-round-to-get-correct-rounding">Using toFixed(2) and math round to get correct rounding</a></p>

<p>also did this process <code>Math.round(value*Math.pow(10,dec))/Math.pow(10,dec);</code></p>

<p>Any ideas?</p>

<p>Thanks</p>

<p>This is my initial test. Though this is just an initial test what I did is checked if the last two digits is greater than 5 then apply <code>Math.ceil</code> that would to the <code>0.255</code> to be <code>0.26</code> but when using <code>39.99</code> the result would still be <code>39.99</code> though <code>39.99</code> should use <code>Math.round</code> so that the result would be <code>40</code>.</p>

<p>What I would like to accomplish is to be able to round up or round down any number if it needs rounding up or if it needs rounding up.</p>

<p><strong>UPDATE</strong></p>

<p>I was able to solve my own problem. (Atleast to my specific environment)</p>

<p><a href="http://jsfiddle.net/xMj3M/4/" rel="nofollow">http://jsfiddle.net/xMj3M/4/</a></p>
