Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorGustavs
    • CommentTimeJul 18th 2006 edited
     permalink
    Hey, I'm trying to get the value to be for example "25.00" but instead the JS rounds the number to 25. How can I set it not to round it?

    Here's the code:

    <script language="JavaScript">
    function calc() {

    var pc = 25.00;
    var price = 0;
    var currency = " Ls";

    if (document.formName.HDD[0].checked==true) {
    var price = 0.00;
    } else if (document.formName.HDD[1].checked==true) {
    var price = 3.30;
    } else if (document.formName.HDD[2].checked==true) {
    var price = 2.21;
    } else if (document.formName.HDD[3].checked==true) {
    var price = 1.00;
    }

    document.formName.textInput.value = pc + price + currency;

    }

    </script>



    PC maksa - 25.00 Ls<br /><br />
    <form name="formName"><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" />
    <input type="radio" value="HDD1" name="HDD" onClick="calc()" checked="checked" />HDD1<br />
    <input type="radio" value="HDD2" name="HDD" onClick="calc()" />HDD2(+3Ls)<br />
    <input type="radio" value="HDD3" name="HDD" onClick="calc()" />HDD3(+2Ls)<br />
    <input type="radio" value="HDD4" name="HDD" onClick="calc()" />HDD4(+1Ls)<br />
    <br />
    <input type="text" name="textInput" value="25.00 Ls" />
    <input type="button" onclick="cent(3)" value="test" />
    </form>
    •  
      CommentAuthorfake
    • CommentTimeJul 18th 2006
     permalink
    This works in modern browsers :
    function calc() {

    var pc = 25.00;
    var price = 0;
    var currency = " Ls";

    if (document.formName.HDD[0].checked==true) {
    price = 0.00;
    } else if (document.formName.HDD[1].checked==true) {
    price = 3.30;
    } else if (document.formName.HDD[2].checked==true) {
    price = 2.21;
    } else if (document.formName.HDD[3].checked==true) {
    price = 1.00;
    }

    document.formName.textInput.value = (pc + price).toFixed(2) + currency;

    }
    • CommentAuthorGustavs
    • CommentTimeJul 18th 2006
     permalink
    Thanks again fake. :)
    •  
      CommentAuthorfake
    • CommentTimeJul 18th 2006
     permalink
    Anytime.
Add your comments
    Username Password
  • Format comments as (Help)