answersLogoWhite

0

In C# you can do that in the following way Convert.ToInt32(yourStringHere), for instance Convert.ToInt32("wikianswers"). But not all string can be converted to int type. If it happens compilator will throw the exception converting error which you can handle using structure try { ...//your code } catch (Exception) { ... //your code in the case of the exception }

User Avatar

Wiki User

16y ago

Still curious? Ask our experts.

Chat with our AI personalities

ViviVivi
Your ride-or-die bestie who's seen you through every high and low.
Chat with Vivi
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
More answers

There's a number of ways you can do it.

variable = variable * 1 multiplies the variable by one, and converts the variable to a number if it's a string. Because * 1 doesn't change the value, this is one way of converting a string into an integer.

Another is using JavaScript's parseInt(variable).

User Avatar

Wiki User

14y ago
User Avatar

You can use the function parseInt() for integers or parseFloat() for decimals.

User Avatar

Wiki User

16y ago
User Avatar

<script type="text/javascript">

somestring = '53';

alert(parseInt(somestring));

</script>

User Avatar

Wiki User

15y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How to convert a string into an integer in javascript?
Write your answer...
Submit
Still have questions?
magnify glass
imp