使用java.text.DecimalFormat格式化整数值
在这里,我们使用Java中的DecimalFormat类来格式化整数值,即java.text.DecimalFormat包。
让我们采用以下格式:DecimalFormat(“0。######E0”)并format()为此使用方法-
new DecimalFormat("0.#####E0").format(5089)
new DecimalFormat("0.#####E0").format(608)由于我们在Java中使用了DecimalFormat类,因此必须将以下包导入-
import java.text.DecimalFormat;
以下是一个例子-
示例
import java.text.DecimalFormat;
public class Demo {
public static void main(String[] argv) throws Exception {
System.out.println(new DecimalFormat("0.#####E0").format(387979));
System.out.println(new DecimalFormat("0.#####E0").format(29797));
System.out.println(new DecimalFormat("0.#####E0").format(49788));
System.out.println(new DecimalFormat("0.#####E0").format(5089));
System.out.println(new DecimalFormat("0.#####E0").format(608));
System.out.println(new DecimalFormat("0.#####E0").format(20));
}
}输出结果
3.87979E5 2.9797E4 4.9788E4 5.089E3 6.08E2 2E1
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短