Pavel Valeriu Pavel Valeriu - 1 year ago 133
Javascript Question

How to convert a string to number using Google Apps Script

I know that I'm asking a dumb question, but I can't figure it out how to convert this string

to a number.


var num = "82144251";

If I try the code below the
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


Just select Tools and then Script Editor...

To see the logs press Ctrl + Enter

Answer Source

You can convert a string to number using unary operator '+' or parseInt(number,10) or Number()

check these snippets

var num = "82144251";
var num2="82144251"

var num3="34";

Hope it helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download