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 给外婆敬酒祝福语简短