Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Convert a Float Number to a Whole Number</title> </head> <body> <script> document.write(Math.trunc(3.5) + "<br>"); // Prints: 3 document.write(Math.trunc(-5.7) + "<br>"); // Prints: -5 document.write(Math.trunc(0.123) + "<br>"); // Prints: 0 document.write(Math.trunc(-1.123) + "<br>"); // Prints: -1 document.write(Math.ceil(3.5) + "<br>"); // Prints: 4 document.write(Math.ceil(-5.7) + "<br>"); // Prints: -5 document.write(Math.ceil(9.99) + "<br>"); // Prints: 10 document.write(Math.ceil(-9.99) + "<br>"); // Prints: -9 document.write(Math.floor(3.5) + "<br>"); // Prints: 3 document.write(Math.floor(-5.7) + "<br>"); // Prints: -6 document.write(Math.floor(9.99) + "<br>"); // Prints: 9 document.write(Math.floor(-9.99) + "<br>"); // Prints: -10 document.write(Math.round(3.5) + "<br>"); // Prints: 4 document.write(Math.round(-5.7) + "<br>"); // Prints: -6 document.write(Math.round(7.25) + "<br>"); // Prints: 7 document.write(Math.round(4.49) + "<br>"); // Prints: 4 </script> </body> </html>