NumberFormat中抛出ParseException的,当我尝试解析“10,10€”。
@Test
public void get_currency_from_text() throws Exception {
String moneyAsString = "10,10 €";
//Do not use double for monetary values
Double moneyAsDouble = 10.10;
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.GERMANY);
Double parsedMoney = formatter.parse(moneyAsString).doubleValue();
assertEquals(moneyAsDouble, parsedMoney);
}
这是什么,当我运行测试我被抛出
java.text.ParseException: Unparseable number: "10,10 €"
每当我这样做,虽然它工作正常:
@Test
public void get_currency_from_text() throws Exception {
Double moneyAsDouble = 10.10;
NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.GERMANY);
String moneyAsString = formatter.format(moneyAsDouble);
Double parsedMoney = formatter.parse(moneyAsString).doubleValue();
System.out.println(moneyAsString);
//10,10 €
assertEquals(moneyAsDouble, parsedMoney);
}
我怀疑它有什么做的空间,但我仍然不知道如何解决它,任何想法?
好像在“10,10€”的空间不是它格式化期待权ASCII。这显然这里(Parse currency with symbol: Not all case working - Java),该格式类期待与代码160的字符是形容为“不间断空格”提及。