Java如何解析语言环境的数字?
package org.nhooo.example.text;
import java.util.Locale;
import java.text.NumberFormat;
import java.text.ParseException;
public class LocaleNumberParse {
public static void main(String[] args) {
try {
//在此示例中,我们尝试解析
//定义的格式。基本上我们想隐蔽字符串
//区域设置为正确的数字值。
Number number =
NumberFormat.getNumberInstance(Locale.JAPAN).parse("25,000.75");
//只需使用解析过程中的数字做一些事情
if (number instanceof Long) {
System.out.println("This number is instanceof Long and the " +
"value is: " + number.longValue());
} else if (number instanceof Double) {
System.out.println("This number is instanceof Double and the " +
"value is: " + number.doubleValue());
}
} catch (ParseException e) {
e.printStackTrace();
}
}
}该代码段打印出以下结果:
This number is instanceof Double and the value is: 25000.75
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短