When I want to parse value from String array to BigDecimal I have this error:
Exception in thread "main" java.text.ParseException: Unparseable number: "86400864008640086400222"
I am searching on internet for the solution how to fix this. Maybe you guys know?
It was not my idea to use BigDecimal but unfortunately I have to. I founded some code which supposed to change value from String to BigDecimal and return it:
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 ());
}
}
Here is my code when try to parse:
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 function open the file with data and read this in this wayL temp+=line+" "; This is the reason why i split by \s. This work for me with Strings and Integers but I have got problem with BigDecimal.
Greetings,