SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Math.Round not working.

    hello,

    i am getting output with this code like 107.25
    but i want only 107 and if 134.67 is there than i want 135
    for that i was tring
    a1= System.Math.Round(a, 0);
    somethings like this. i think i am miss placing this value.

    this is my code:
    Code JavaScript:
    function calculate() {
    function isaN(str) {
    	if(parseInt(str) != str){
    	     return false;
      	}
      	return true;
    }
    if (document.cal.age.value == "") {
    alert("Please enter an age")
    document.cal.age.focus()
    return false
    }
    else if((document.cal.age.value !="") && (isaN(document.cal.age.value)==false))
    	{
    		alert("Please enter your valid Age");
    		document.cal.age.focus();
    		return false;
    	}
    else {
    var age = 0;
    var max = 0;
    var a = 0;
    var b = 0;
    var c = 0;
     
    document.getElementById("max").innerHTML= "";
    document.getElementById("a").innerHTML= "";
    document.getElementById("b").innerHTML= "";
    document.getElementById("c").innerHTML= "";
     
     
        age = document.cal.age.value * 1;
     
    max = 220 - age;
    a = max * .65;
    b = max * .75;
    c = max * .85;
     
    a1= System.Math.Round(a, 0);
    b1= System.Math.Round(b, 0);
    c1=System.Math.Round(c, 0);
    document.getElementById("max").innerHTML= "<b>" + max + "</b>";
    document.getElementById("a").innerHTML= "<b>" + a1 + "</b>";
    document.getElementById("b").innerHTML= "<b>" + b1 + "</b>";
    document.getElementById("c").innerHTML= "<b>" + c1 + "</b>";
     
    }
    }
     
    function clearIt() {
    document.getElementById("max").innerHTML= "";
    document.getElementById("a").innerHTML= "";
    document.getElementById("b").innerHTML= "";
    document.getElementById("c").innerHTML= "";
     
    }
     
    // Stop Hiding -->
    </script>

    could you please tell me how can i do this?
    thanks in advace.

  2. #2
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey i got the answer.

    Code JavaScript:
    a = Math.round(max * .65)   ;
    b = Math.round(max * .75);
    c = Math.round(max * .85);

    I hope anyone is looking for this. it may help him/her

    thank you.


Bookmarks

Posting Permissions

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