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
热门推荐
9 庆双节祝福语简短
10 天气转凉祝福语简短
11 最真的新春祝福语简短
12 除夕的拜年祝福语简短
13 六一祝福语简短感动女生
14 节日祝福语幽默简短的
15 美丽晚霞祝福语简短句
16 生日牌祝福语英语简短
17 情人表白祝福语简短大气
18 英语简短祝福语给学生