2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Google App Script】文字列⇄数値のデータ型変換

Posted at

GoogleAppScriptにおける、文字列型と数値型の変換方法について記載します。

主なシチュエーションとして、Googleスプレッドシートからデータを取得した際に、データが文字列型で取得されるため、それを用いた数値演算を行う時なんかに、文字列→数値の型変換を実施することが考えられます。
逆方向の変換となる、数値→文字列の型変換も同時に見ていきましょう。

文字列型→数値型

文字列型の変数に対して、Number型でキャストしてあげるだけです。

toNumber.gs
var str = "10";
var num = Number(str);

数値型→文字列型

逆方向も同様の考え方で、数値型の変数に対して、String型でキャストしてあげるだけです。

toString.gs
var num = 10;
var str = String(num);

参考記事

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?