Round variable to 1 decimal using javascript - Javascript Data Type

Javascript examples for Data Type:decimal

Description

Round variable to 1 decimal using javascript

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*w ww  .  ja  v a2s .co m*/
var my = 0;
show_value();
setInterval(function(){
    my += 0.2;
    show_value();
}, 1000);
function show_value(){
    document.getElementById("co").innerHTML = Math.round(my * 10) / 10;
}
    }

      </script> 
   </head> 
   <body> 
      <li>
         <label id="co"></label>
         CO?
      </li>  
   </body>
</html>

Related Tutorials