5
5

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 数値から文字列への変換&進数指定

Last updated at Posted at 2016-02-03

はじめに

事前に準備する外部ライブラリ等はありません。

実装例

サンプルでは、動作確認しやすいようにmainメソッドで実行できるようにしてあります。

LongToString.java
/**
 *
 * @author tool-taro.com
 */
public class LongToString {

	public static void main(String[] args) {

		//変換したい数値
		Long source = 123456789L;
		//変換時の進数
		int radix = 36; //数値+アルファベット小文字の36進数

		//変換処理
		String result = Long.toString(source, radix);
		//標準出力
		System.out.format("変換結果=%1$s", result);
	}
}

動作確認

$ javac LongToString.java
$ java LongToString
$ 変換結果=21i3v9

通番をIDに使う際など、文字列表現を短縮すると便利なシーンで使えます。

環境

  • 開発

    • Windows 10 Pro
    • JDK 1.8.0_112
    • NetBeans IDE 8.2
  • 動作検証

    • CentOS Linux release 7.2
    • JDK 1.8.0_112

Webツールも公開しています。
Web便利ツール@ツールタロウ

5
5
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
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?