Javascript - Calculating monetary totals
<p>I have a page on a site that calculates rate totals for a rental, which are optional. The javascript serves nothing more but to show you the updated total if you select or unselect checkbox options.</p>

<p>Here is what I've tried. It appears to work, but it is adding 2 cents to every other click for one of the checkboxes, I believe because toFixed rounds. How can I keep the number from rounding?</p>

<pre><code>function update_rate(state, amount, field) {
        if (state == true) {
            rate = parseFloat($('span.rateTotal').text()) + amount;
            rate = rate.toFixed(2);
            due = parseFloat($('span.'+field).text()) + amount;
            due = due.toFixed(2);
            $('span.rateTotal').text(rate);
            $('span.'+field).text(due);
        } else {
            rate = parseFloat($('span.rateTotal').text()) - amount;
            rate = rate.toFixed(2);
            due = parseFloat($('span.'+field).text()) - amount;
            due = due.toFixed(2);
            $('span.rateTotal').text(rate);
            $('span.'+field).text(due);
        }
    }
</code></pre>

<p>Checkbox HTML:</p>

<pre><code>&lt;cfinput type="checkbox" name="linen_service" id="linen_service" checked="checked" value="0" onClick="update_rate(this.checked, #reservationQuery[7].xmlChildren[i]['dblAmount'].xmlText#, 'second-due');" /&gt;
</code></pre>

<p>Basically passes in the amount of the option, checkbox state, and the name of the field that should be affected.</p>

<p>Edit: Fiddle URL: <a href="http://jsfiddle.net/nGrVf/6/" rel="nofollow">http://jsfiddle.net/nGrVf/6/</a></p>
