Home > Web Front-end > JS Tutorial > body text

How to convert decimal to integer in javascript

coldplay.xixi
Release: 2021-04-15 16:54:06
Original
2363 people have browsed it

How to convert decimals to integers in javascript: First create a new file and use the input tag to create a number input box; then set the id attribute of the input tag to data and use the button tag to create a button; then use the value attribute to obtain the input box number; finally check the results in the browser.

How to convert decimal to integer in javascript

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to convert decimals to integers in javascript:

Create a new html file named test.html to explain how to convert decimals to integers in javascript.

How to convert decimal to integer in javascript

In the test.html file, use the input tag to create a number input box for testing.

How to convert decimal to integer in javascript

In the test.html file, set the id attribute of the input tag to data, which is used to obtain the input object below.

How to convert decimal to integer in javascript

In the test.html file, use the button tag to create a button, bind the onclick click event to the button, and when the button is clicked, execute the getZs() function.

How to convert decimal to integer in javascript

In the js tag, create the getZs() function. Within the function, obtain the input object through the id, use the value attribute to obtain the number of the input box, and then use the Math object The round() method converts the number to an integer and uses the alert() method to output the result.

How to convert decimal to integer in javascript

Open the test.html file in the browser, enter the number, click the button to view the result.

How to convert decimal to integer in javascript

Related free learning recommendations: javascript video tutorial

##

The above is the detailed content of How to convert decimal to integer in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!