How can I convert a variable to an integer in _ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I convert a variable to an integer in _

in html but not in html5

17th Feb 2017, 5:57 PM
Gyayak
2 Answers
0
use parseInt e.g var a = 45 as numbers are displayed in double precision so while document.write(a) it will.display as 45.00 so to convert to int just do these var a = parseInt(45) will display it as int 45 hope it helps cheers .. !
17th Feb 2017, 6:18 PM
Amit Ghatge
Amit Ghatge - avatar
0
When will the number be sipalyed as 45.00 as if declared in a function it will just show two digits? <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button onclick="myFunction()">Go!</button> <p id="show"></p> <script> function myFunction() { var num = 45 document.getElementById("show").innerHTML = num; } </script> </body> </html>
17th Feb 2017, 7:33 PM
Trouty McSquire
Trouty McSquire - avatar