Convert string with leading zeros, for example "0123", to a number in JavaScript

Description

The following code shows how to convert string with leading zeros, for example "0123", to a number.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var num = Number("0123")
document.writeln(num);
<!-- w ww  . j a v  a  2  s .  c o m-->
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Convert string with leading zeros, for example "0123", to a number in JavaScript
Home »
  Javascript Tutorial »
    Data Type »
      Number Convert
Javascript Tutorial Number Convert
Convent undefeind to NaN with Number functi...
Convert Number to String with radix in Java...
Convert Number to string in base 10 (decima...
Convert Number to string in base 16 (hexade...
Convert Number to string in base 2 (binary ...
Convert Number to string in base 8 (octal n...
Convert String with only number and plus si...
Convert String with only number to number w...
Convert empty string("") to 0 in JavaScript
Convert false value to 0 with Number functi...
Convert float whole number into an integer ...
Convert null value to 0 with Number functio...
Convert number in specific precision in Jav...
Convert number to exponential format in Jav...
Convert number to primitive with Number val...
Convert number to string with Number.toStri...
Convert number to string with a specified P...
Convert number to string with a specified n...
Convert number to string with toLocaleStrin...
Convert string to number with Number constr...
Convert string with eading zeros and decima...
Convert string with hexadecimal format and ...
Convert string with hexadecimal format, suc...
Convert string with leading zeros and minus...
Convert string with leading zeros and plus ...
Convert string with leading zeros, for exam...
Convert string with not a number value, for...
Convert string with valid floating-point fo...
Convert string with valid floating-point fo...
Convert string with valid floating-point fo...
Convert true value to 1 with Number functio...