【发布时间】:2016-10-17 23:22:34
【问题描述】:
我有一个字符串“R$3.333,33”,我正在尝试使用此方法将其解析为双精度值:
public static BigDecimal parse(final String amount, final Locale locale) throws ParseException {
final NumberFormat format = NumberFormat.getCurrencyInstance(locale);
if (format instanceof DecimalFormat) {
((DecimalFormat) format).setParseBigDecimal(true);
}
return (BigDecimal) format.parse(amount.replaceAll("[^\\d.,]", ""));
}
但我得到一个例外,上面写着:
W/System.err: java.text.ParseException: Unparseable number: "3.333,33" (at offset 8)
我的使用方式如下:
Ferramentas.parse(value.getText().toString(), Locale.FRANCE)
【问题讨论】:
-
您使用的是哪个语言环境?
-
@m0skit0 我正在使用 Locale.FRANCE
-
@MarceloVinícius 这个答案对成千上万的
.不起作用,它会打印3。
标签: java android parsing currency