「Java」DecimalFormatとLong.parseLong()の使い方

構文
1.public DecimalFormat(String pattern)
パラメータ:pattern – ローカライズされていないパターン文字列。

2.public static long parseLong(String s)
throws NumberFormatException
パラメータ:
s – 解析対象のlong表現を含むString
戻り値:
10進数の引数で表されるlong。

Javaコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.arkgame.study;
import java.text.DecimalFormat;
public class DecimalFormatDemo {
public static void main(String[] args) {
DecimalFormat fmt = new DecimalFormat("#,###");
String cft = "1234567";
String num = null;
long numVal = 0;
try {
numVal = Long.parseLong(cft);
num = fmt.format(numVal);
System.out.println("結果:\n" + num);
} catch (IllegalArgumentException ie) {
}
}
}
package com.arkgame.study; import java.text.DecimalFormat; public class DecimalFormatDemo { public static void main(String[] args) { DecimalFormat fmt = new DecimalFormat("#,###"); String cft = "1234567"; String num = null; long numVal = 0; try { numVal = Long.parseLong(cft); num = fmt.format(numVal); System.out.println("結果:\n" + num); } catch (IllegalArgumentException ie) { } } }
package com.arkgame.study;

import java.text.DecimalFormat;

public class DecimalFormatDemo {

      public static void main(String[] args) {

            DecimalFormat fmt = new DecimalFormat("#,###");
            String cft = "1234567";
            String num = null;

            long numVal = 0;
            try {
                  numVal = Long.parseLong(cft);
                  num = fmt.format(numVal);
                  System.out.println("結果:\n" + num);
            } catch (IllegalArgumentException ie) {

            }
      }
}

結果:
1,234,567

Java

Posted by arkgame