C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Converting from number to string gives strange number in Javascript

By : Andrey
Date : November 19 2020, 12:41 AM
should help you out Any numeric constant prefixed with a 0 is an octal literal (assuming all its digits are valid octal digits).
code :
``````var i = 010; // 8 decimal
``````

Share :

## Javascript: Converting String to Number?

By : Christiane Horntrich
Date : March 29 2020, 07:55 AM
this one helps. Try str = parseInt( str, 10 )
(note: the second parameter signifies the radix for parsing; in this case, your number will be parsed as a decimal)

## Javascript - Leading zero to a number converting the number to some different number. not getting why this happening?

By : Arjun Shamsunder
Date : March 29 2020, 07:55 AM
Hope that helps If there is a leading 0, it is converting it to octal (base 8) as long as its a valid number in base 8 (no numbers greater than 7).
For example:

## Javascript converting number to string turns it into another number?

By : Armando Pimentel
Date : March 29 2020, 07:55 AM
Any of those help If I try to convert 003050 to a string it turns it into 1576 how can I turn 003050 into a string without it doing that. And any other possible whole number? I tried '' + 003050 and it's still 1576 , This has no relation with the conversion to string.
code :
``````var n = 003050;
``````
``````var n = 3050;
``````
``````var s = "003050";
``````

## Javascript Number-String DIV onclick strange conversion

By : Mixalis Tetteris
Date : March 29 2020, 07:55 AM
Does that help What I basically do is that I assign the Facebook-ID from a person to a onclick-Event in a DIV. The div is a string itself because I assign it later to a DOM-property via innerHTML , Maybe you should try
code :
``````"<div onclick='openFbFriend(\"" + friendsArray[i]['facebookID'] + "\");' class='row'>";
``````
``````<div onclick='openFbFriend("10204840506352732");' class='row'>
``````
``````<div onclick='openFbFriend(10204840506352732);' class='row'>
``````

## Javascript converting string to number only if the string is an number

By : Roman Orlov
Date : March 29 2020, 07:55 AM
Hope this helps You could check if the stringed numerical value is equal to the value.
code :
``````var array = ["0", "0.5", "100", "abc", " "];

console.log(array.map(a => (+a).toString() === a ? +a : a));``````
``.as-console-wrapper { max-height: 100% !important; top: 0; }``