如何使用Google Apps脚本将字符串转换为数字 [英] How to convert a string to number using Google Apps Script

查看:258
本文介绍了如何使用Google Apps脚本将字符串转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我在问一个愚蠢的问题,但我无法弄清楚如何将此字符串 82144251 转换为数字。



代码:

  var num =82144251; 

如果我尝试 .toFixed()函数将我的数字转换回字符串...

问题更新:
我正在使用google apps脚本编辑器,而且必须是问题...

  num = parseInt(num).toFixed()//如果我只是做了parseInt(num) 8.2144251E7 


解决方案

运算符'+'或parseInt(number,10)或Number()



检查这些片段

  var num =82144251; num = + numconsole.log(num); var num2 =82144251console.log(parseInt(num,10 )); var num3 =34; console.log(Number(num3));  

希望它有帮助


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

解决方案

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

check these snippets

var num = "82144251";
num=+num
console.log(num);
var num2="82144251"
console.log(parseInt(num,10));

var num3="34";
console.log(Number(num3));

Hope it helps

这篇关于如何使用Google Apps脚本将字符串转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆