帮忙解答一道多选题

来源:百度知道 编辑:UC知道 时间:2024/05/31 20:24:26
How can you handle input of different decimal symbols—for example, 543,6 as opposed to 543.6?

(a) Use NumberFormat and its methods format() and parse(). This will handle the default locale for you.

(b) Use Format and its methods format() and parse(). This will handle the default locale for you.

(c) Use DecimalFormat and its methods format() and parse(). This will handle the default locale for you.

(d) Use Format and its methods numberformat() and numberparse(). This will handle the default locale for you.

Select all right answers

正确答案应该是a和c 吧!

NumberFormat 是所有数值格式的抽象基类。此类提供格式化和解析数值的接口。NumberFormat 还提供了一些方法来确定哪些语言环境具有数值格式,以及它们的名称是什么。

NumberFormat 可用于格式化和解析任何语言环境的数值。使代码能够完全独立于小数点、千位分隔符甚至所用特定小数位数的语言环境约定,并与数值格式是否为偶小数无关。

若要格式化当前 Locale 的数值,可使用其中一个工厂类方法:

myString = NumberFormat.getInstance().format(myNumber);
如果格式化多个数值,那么获取该格式并多次使用它是更为高效的做法,这样系统就不必多次获取关于语言环境语言和国家/地区约定的信息了。
NumberFormat nf = NumberFormat.getInstance();
for (int i = 0; i < myNumber.length; ++i) {
output.println(nf.format(myNumber[i]) + "; ");
}

DecimalFormat 是 NumberFormat 的一个具体子类,用于格式化十进制数字。该类设计有各种功能,使其能够解析和格式化任意语言环境中的数,包括对西方语言、阿拉伯语和印度语数字的支持。它还支持不同类型的数,包括整数 (123)、定点数 (123.4)、科学记数法表示的数 (1.23E4)、百分数 (12%) 和金额 ($123)。所有这些内容都可以本地化。

要获取具体语言环境的 NumberFormat(包括默认语言环境),可调用 NumberFormat 的某个工厂方法,如 getInstance()。通常不直接调用 DecimalFormat 的构造方法,因为 NumberFormat 的工厂方法可能返回不同于 DecimalFormat 的子类。如果需要自定义格式对象,可执行:

NumberFormat f = NumberFor