当我想将字符串数组中的值解析为 BigDecimal 时,出现此错误:
Exception in thread "main" java.text.ParseException: Unparseable number: "86400864008640086400222"
我正在互联网上搜索如何解决此问题的解决方案。也许你们知道吗?
使用 BigDecimal 不是我的想法,但不幸的是我必须这样做。我创建了一些代码,应该将值从 String 更改为 BigDecimal 并返回它:
public static BigDecimal parseCurrencyPrecise (String value) throws ParseException
{
NumberFormat format = NumberFormat.getCurrencyInstance ();
if (format instanceof DecimalFormat)
((DecimalFormat) format).setParseBigDecimal (true);
Number result = format.parse (value);
if (result instanceof BigDecimal)
return (BigDecimal) result;
else {
// Oh well...
return new BigDecimal (result.doubleValue ());
}
}
这是我尝试解析时的代码:
public void Function() throws ParseException {
String [] array;
array=OpenFile().split("\\s");
for(int i = 10 ;i < array.length; i+= 11) {
BigDecimal EAE = parseCurrencyPrecise(array[i]);
System.out.println(EAE);
}
}
OpenFile函数用数据打开文件,这样读取这个L temp+=line+" "; 这就是我用\s分割的原因。这对我来说适用于字符串和整数,但我遇到了 BigDecimal 的问题。
问候,