i)String to Integer
Syntax: parseInt(string, radix)
To convert a value from string to integer we have to use the function or method parseInt().If the string begins with "0x", the radix is 16 (hexadecimal)
If the string begins with "0", the radix is 8 (octal).
If the string begins with any other value, the radix is 10 (decimal)
Example
<html>
<body>
<script type="text/javascript">
<body>
<script type="text/javascript">
document.write(parseInt("35.49") + "<br />");
document.write(parseInt("35.00000000")+ "<br />");
document.write(parseInt("35") + "<br />");
document.write(parseInt("0x35")+ "<br />");
document.write(parseInt("035")+ "<br />");
document.write(parseInt("Hello")+ "<br />");
</script>
</body>
</html>
Output
Click the buttons below and see what outputs give.
No comments:
Post a Comment