2
2

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 5 years have passed since last update.

java > link > 数値をString型に変換する > valueOf() / String.format("%05d", yournumber); / 文字列連結演算子 +

Last updated at Posted at 2016-08-04

数値をString型に変換したい。

ValueOf()

valueOf()を使うようだ。

0パディング

左を0で埋める方法。
http://stackoverflow.com/questions/473282/how-can-i-pad-an-integers-with-zeros-on-the-left

String.format("%05d", yournumber);

/* package whatever; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int value = 314;
		String msg = String.format("%05d", value);
		System.out.println(msg);
	}
}
結果
00314

文字列連結演算子 +

@shiracamus さんのコメントにて「文字列連結演算子」を教えていただいた。

情報感謝。

2
2
2

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?