Find value before and after decimal point - Javascript Data Type

Javascript examples for Data Type:decimal

Description

Find value before and after decimal point

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() {//from w  ww  .ja  v a2 s  .  co m
function getNatural(num) {
    return parseFloat(num.toString().split(".")[0]);
}
function getDecimal(num) {
    return parseFloat(num.toString().split(".")[1]);
}
var a = 12345.67;
console.log(getNatural(a)); ///before dot
console.log(getDecimal(a)); ///after dot
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials