Can anyone help me with the following Javascript. I am going crazy trying to figure this out because it should be easy. Basically I want to calculate the percentage of a number, but I'm getting a really weird result. In the following code f is equal to 3 and x.length is equal to 8. The part that isn't working is emphasised in bold. Basically 3/8 * 100 should result in 37.5 but the result I am getting with the following code is 7934570.3125. How do you calculate this percentage in Javascript?
Code:
function displaymember()
{
var m = 1;
var f = 1;
for(i=0;i<x.length;i++)
{
sex=(x[i].getElementsByTagName("sex")[0].childNodes[0].nodeValue);
if (sex=="Male")
{
m++;
}
else
{
f++;
}
percent=f/x.length * 100
document.getElementById("fixed").innerHTML=percent;
}
}