Writing a float value to a file

I am trying to write a float value to a file on a SD card. I don't understand why serial.println(float) on works, but file.println(float) does not.

If someone can explain this I'd be most grateful. I've tried looking at dtostrf, but honestly I cannot find it in the reference.

Thanks.

I don't have an SD shield. Can you define "doesn't work"? Do you mean "doesn't compile", or "compiles, but doesn't write to the file"?

It compiles but does not write any output.

Are you using the SD library? According to the File.println() reference page (http://arduino.cc/en/Reference/FilePrintln), it doesn't support floating point numbers:

data (optional): the data to print (char, byte, int, long, or string)

dxw00d: Are you using the SD library? According to the File.println() reference page (http://arduino.cc/en/Reference/FilePrintln), it doesn't support floating point numbers:

data (optional): the data to print (char, byte, int, long, or string)

Yes, so whats the solution?

After reviewing floattostring.h threads the suggested method is to use:

String tempC = dtostrf(celsius, 10, 2, 10);

However this generates errors...

 error: invalid conversion from 'int' to 'char*'
 error: initializing argument 4 of 'char* dtostrf(double, signed char, unsigned char, char*)'

fmpc001: After reviewing floattostring.h threads the suggested method is to use:

String tempC = dtostrf(celsius, 10, 2, 10);

Why would the suggested method be something that is wrong?

The parameters for dtostrf says that the last argument is a character-buffer. You passed a 10. The compiler is telling you that it expected the last argument to be a character array.

dtostrf(floatVar, minStringWidthIncDecimalPoint, numVarsAfterDecimal, charBuf);

So you probably wanted to do: char buffer[14]; // 10 min string with, decimal, 2 characters after decimal, plus a \0 dtostrf(celsius, 10, 2, buffer);

Then print buffer.