Monday, June 3, 2024
162
rated 0 times [  168] [ 6]  / answers: 1 / hits: 134632  / 8 Years ago, fri, november 18, 2016, 12:00:00

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

More From » google-apps-script

 Answers
3

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



check these snippets





var num1a = 1;
console.log(+num1a);

var num1b = 2;
num1b=+num1b;
console.log(num1b);


var num3 = 3
console.log(parseInt(num3,10));


var num4 = 4;
console.log(Number(num4));





Hope it helps


[#60002] Thursday, November 17, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jadyngraysons

Total Points: 455
Total Questions: 109
Total Answers: 98

Location: Trinidad and Tobago
Member since Fri, May 8, 2020
4 Years ago
jadyngraysons questions
Thu, Apr 23, 20, 00:00, 4 Years ago
Sat, Jan 18, 20, 00:00, 4 Years ago
Tue, Dec 31, 19, 00:00, 5 Years ago
;