How to convert a float number to int number in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
<head>  
</head>
  
<body>
<p id="calc"></p>
<script>
function float_to_int(n) 
{
    return parseInt(n);
}
function print_float_to_int(n) 
{
    document.getElementById("calc").innerHTML = float_to_int(n);
}
</script>
<input type="button" value="float_to_int(123.35)" onclick="print_float_to_int(123.35)" />
<input type="button" value="float_to_int(123.39)" onclick="print_float_to_int(123.39)" />
<input type="button" value="float_to_int(123.11)" onclick="print_float_to_int(123.11)" />
 
  
</body>
</html>

<!-- 
run:

123
123
123
-->

 



answered Dec 15, 2015 by avibootz
...