how to round off decimal point

Discussion in 'General Computer Support' started by arianne75, Jun 8, 2007.

  1. arianne75


    Jun 8, 2007
    Likes Received:
    not a programmer but got this code to calculate rates. my problem is, i need to round off the amounts to just two numbers after the decimal. can someone please help me. below is the code for the calculator, please let me know what and where to insert the code to truncate the decimals.

    <script type="text/javascript">
    function calculate() {
    var b1 = parseFloat(document.getElementById("cons").value * 0.0024);
    var s1 = (1 * 22.00);
    var before = parseFloat(document.getElementById("rsch").value);
    var after = before + b1 +s1;
    document.getElementById("before").value = before;
    document.getElementById("after").value = after;
    document.getElementById("s1").value = s1;
    document.getElementById("b1").value = b1;

    Consumption Usage: <input type="text" id="cons"/><br/>
    Rate Schedule : <select id="rsch"><br/>
    <option value="7.46">R1</option>
    <option value="8.71">R2</option>
    <option value="13.67">R3</option>
    <option value="17.41">R4</option>
    <option value="31.09">R5</option>
    <option value="43.52">R6</option>
    <option value="80.82">R7</option>
    <option value="161.65">R8</option>
    <option value="192.73">R9</option>
    <button onclick="calculate();">Calculate</button><br/>

    Water Service Charge : <input type="text" id="before" disabled="true"/><br/>
    Water Charge : <input type="text" id="b1" disabled="true"/><br/>
    Sewer Residential Lifeline: <input type="text" id="s1" disabled="true"/><br/>
    Total Bill Amount : <input type="text" id="after" disabled="true"/><br/>
    arianne75, Jun 8, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.