www.webdeveloper.com
Results 1 to 12 of 12

Thread: Rounding answer DOWN to 2 decimal places / use dollar sign

Threaded View

  1. #1
    Join Date
    Jul 2003
    Location
    Louisiana
    Posts
    326

    Rounding answer DOWN to 2 decimal places / use dollar sign

    Here is my code:

    Code:
    <script type="text/javascript" language="Javascript">
    
    var v1 = 0;
    var v2 = .00939740;
    var answer = 0;
    
    function calculate () {
    // The Calculation: change operator in this equation to change the calculation
    answer = v1 * v2;
    
    var elem;
    elem = document.getElementById("v1");
    elem.value = v1;
    elem = document.getElementById("v2");
    elem.value = v2;
    
    elem = document.getElementById("answer");
    elem.value = answer;
    }
    
    function setValue(elem) {
    var val = 0.0;
    if (elem.value != "") {
    val = parseFloat(elem.value);
    }
    else {
    val = 0.0;
    }
    switch (elem.id) {
    case "v1": v1 = val; break;
    case "v2": v2 = val; break;
    }
    calculate();
    }
    </script>
    Right now, it displays my answer as a 15 decimal place number. I want it to be a 2 decimal place number and I want it to round down.

    And, is there a way to have it display with a dollar sign in front?

    Lastly, is there a way to have it display with the answer yellow highlighted?

    (I am not a programmer, I just make do!)
    Last edited by Duke Will; 04-29-2012 at 03:04 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles