Hi i have a CSV file that contains rows like this
Jacop , "Assistant",150,75
i want to convert 3rd column to 150.75 in java
Should i write a function for this .Or is there another way?
thanks
Hi i have a CSV file that contains rows like this
Jacop , "Assistant",150,75
i want to convert 3rd column to 150.75 in java
Should i write a function for this .Or is there another way?
thanks
Quick idea:
UBe careful of floating point arithmetic errors, but this is the right idea:
int a = Integer.valueOf("150"); // Since your numbers are coming from a CSV
int b = Integer.valueOf("75");
double c = c = (a * 100 + b) / 100.0;
=> 150.75
Note, the value if 100 is there assuming that your number to the right of the decimal is always two digits. So, if that isn't constant, don't use this answer.
Simple regular expression search and replace in your text file (using sed or whatever) to convert the last comma to a decimal point should work fine.
Then use opencsv to pull it all in: