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 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短