Java中的NumberFormat类
NumberFormat可帮助您格式化和解析任何语言环境的数字。它是所有数字格式的抽象基类。
以下是NumberFormat类的一些方法-
覆盖Cloneable。
重写equals。
格式的专业化。
格式的特殊化。
格式的专业化。
格式的特殊化。
示例
现在让我们看一个实现NumberFormat类的示例-
import java.text.NumberFormat;
import java.util.Locale;
public class Demo {
public static void main(String[] args) {
NumberFormat n = NumberFormat.getCurrencyInstance(Locale.FRANCE);
double points = 2.15;
double totalPoints = points * 1000;
System.out.println(n.format(points));
System.out.println(n.format(totalPoints));
}
}输出结果
这将产生以下输出-
2,15 € 2 150,00 €
示例
现在让我们来看另一个示例-
import java.text.NumberFormat;
import java.util.Locale;
public class Demo {
public static void main(String[] args) {
Locale enLocale = new Locale("en", "US");
Locale daLocale = new Locale("da", "DK");
NumberFormat numberFormat = NumberFormat.getInstance(daLocale);
System.out.println(numberFormat.format(100.76));
numberFormat = NumberFormat.getInstance(enLocale);
System.out.println(numberFormat.format(100.76));
}
}输出结果
这将产生以下输出-
100,76 100.76
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短