I know that I'm asking a dumb question, but I can't figure it out how to convert this string 82144251
to a number.
Code:
var num = "82144251";
If I try the code below the .toFixed()
function converts my number back to a string...
Question update: I'm using the google apps script editor and that must be the issue...
num = parseInt(num).toFixed() // if I just do parseInt(num) it returns 8.2144251E7
No questions are dumb.
a quick answer:
to convert a string to a number you can use the unary plus.
Doing
num = +num
is practically the same as doingnum = num * 1;
it converts the value in a to a number if needed, but after that it doesn't change the value.It looks like you're looking for the
Number()
functionality here:You can read more about
Number()
here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberHope this helps!
You can convert a string to number using unary operator '+' or parseInt(number,10) or Number()
check these snippets
Hope it helps
I use num-0, since it is easier for inline use.
var intNum = parseInt("82144251", 10); // intNum is number