Reading CSV file from SD card

Hi all,
Yes I'm a newbie in Arduino and programming in general. To cut it short, I'm facing a problem to read the CSV file from the SD card. The file is actually a series of Longitude and Latitude data of a route. Here is the example of the data:

(Longitude, Latitude)
4530.3979, 909.8869
4530.3980, 909.8866
and so on...

I have managed to get the data printed on the serial monitor, but the readings are somehow inaccurate (some corrects, some are not). Here is the part of the code that I believed need to be fixed.

.......

Serial.println(a);
char buf[a.length();
a.toCharArray(buf,a.length());
Wval=atof(buf);

Serial println(Wval,4);

.......

And this is part of readings I got;
4530.3979
4530.3969
909.8869
909.8869

I'm not sure why it gives different reading from the file. Really appreciate if somebody can help me out with this. Thank you.

Please read the 2 posts at the top of this forum by Nick Gammon giving advice on how to get help here then post your complete program using code tags.

In the meantime, you should realise that floats do not provide great accuracy especially when converted from other formats and that using Strings is not always a good idea. Why use a String, convert it to an array of chars then convert it to a float when you could just use an array of chars ? Are you sure that you need to convert it to float anyway ? Why not just print the char array ?

Am_chemy:
I'm facing a problem to read the CSV file from the SD card.

I think you might be making the problem bigger than it really is.

If your intention is to dump the file contents somewhere else, i.e. another device, check the File Dump exercise in the SD section of the examples. It may be all you need. The vital code is

if (dataFile) {
    while (dataFile.available()) {
      Serial.write(dataFile.read());
    }
    dataFile.close();
  }