I have an array of Strings where one index specifically the 7th one, needs to be a double number so I could use a conditional on it.
while (s.hasNextLine()) {
String customer = s.nextLine();
String[] fields = customer.split("\\|");
double score = Double.parseDouble(fields[7]);
}
Also gave this a try, but no luck. Still the same error.
while (s.hasNextLine()) {
String customer = s.nextLine();
String[] fields = customer.split("\\|");
if (Double.parseDouble(fields[7]) > 5.00) {
The fields[7] contains all the numbers in my input file but how do I make them double values in order to use a conditional on them in an if statement. All the other indexes must stay at strings however.
Doing this causes this error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "$280.80"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at CollectionLetter.main(CollectionLetter.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
SOLUTION: THE ANSWER WAS THAT I HAD CURRENCY SYMBOLS AND I WAS TRYING TO PARSE IT STILL, I SIMPLY USED:
if (Double.parseDouble(fields[7].replace("$","")) > 5.00) {
THANK YOU EVERYONE!