【发布时间】:2018-09-06 03:48:03
【问题描述】:
我正在尝试解析以下字符串:“59000,00”
在巴西,逗号用于表示小数位,小数点用作分隔千位的符号。
我正在尝试做的事情:
final String price = "59000,00";
// LocaleUtils.getLocale returns new Locale("pt", "BR")
final NumberFormat numberFormat = NumberFormat.getCurrencyInstance(LocaleUtils.getLocale());
try {
final double d = numberFormat.parse(price).doubleValue();
// do stuff
} catch (ParseException e) {
// do stuff
}
但是,我收到了 ParseException。为什么会这样?
java.text.ParseException: Unparseable number: "59000,00" (at offset 8)
【问题讨论】:
-
而你的代码没有返回预期的输出,抛出异常,还有别的吗?你没有问任何问题。
-
@luk2302 天哪!我遇到了一个例外,忘记在问题中提及这一点!已编辑。
标签: java string parsing format currency