Files
ASDV-WebDev/Assignments/JavaScript/ch05/ch05/ex_5_5.html
2023-03-22 13:49:03 -05:00

38 lines
1.2 KiB
HTML
Executable File

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Example 5.5</title>
<script>
function floatToInteger()
{
var floatNum = 0; var newValue = 0;
var change = " ";
floatNum = prompt("Enter any number or enter -99 to quit:", "");
while (floatNum != -99)
{
document.write("<p>You originally entered: " + floatNum + "</p>");
newValue = parseInt(floatNum);
document.write("<p>The result of pareseInt(X) is: " + newValue + "</p>");
newValue = Math.floor(floatNum);
document.write("<p>The result of Math.floor(X) is : " + newValue + "</p>");
newValue = Math.ceil(floatNum);
document.write("<p>The result of Math.ceil(X) is : " + newValue + "</p>");
newValue = Math.round(floatNum);
document.write("<p>The result of Math.round(X) is : " + newValue + "</p>");
floatNum = prompt("Enter any number or enter -99 to quit:", "");
}
}
</script>
</head>
<body>
<table align ="center" width ="70%"><tr><td colspan ="2">
<h1>&nbsp;</h2>
<h1>Using Math Methods to Convert Floating Point Numbers to Integers</h1>
<tr><td><p>&nbsp;</p>
<p><input type="button" id="integers" value="Begin" onclick="floatToInteger();" /></p>
</td></tr>
</table>
</body>
</html>