Reputation:
Hi I'm trying to limit the number of decimal places behind the result from this counter. I've tried toFixed but couldn't get it to work... I'm new to this and any help would be much appreciated.
Thanks!
Joseph
<script type="text/javascript">
var counttx= "";
var counterrx=setInterval(timerrx, 1000);
function timerrx()
{
counttx = +counttx + .607028;
if (counttx < 0)
{
clearInterval(counterrx);
return;
}
document.getElementById("timerrx").innerHTML=counttx;
}
</script>
Upvotes: 1
Views: 85
Reputation: 2610
toFixed is not working probably because you declared counttx as string, try this at the end :
document.getElementById("timerrx").innerHTML= Number(counttx).toFixed(2);
Upvotes: 1
Reputation: 707218
.toFixed()
is the right function to use:
document.getElementById("timerrx").innerHTML = counttx.toFixed(2);
Working demo: http://jsfiddle.net/jfriend00/HdJWD/
Upvotes: 0