How to write float value in EEPROM

And yet, we should know why your codes did not work:

1. The syntax of EEPROM.write() command is:
EEPROM.write(address, byteData);

That means the allowable data range is: 0 to 255 (1-byte = 0x00 to 0xFF) -- only integer value and no fractional part.

2. When there is a floating point number (having integer and fractional part) like float x = 13.67, then four consecutive memory locations are needed to store the value of x. The said four memory locations will hole 32-bit (4x8) data which are genertaed according to binary332/IEEE-754 standard (Fig-1).

IEEE754Float
Figure-1:

3. Using write() method, we can store the value x of Step-2 by executing the following codes:

  float x = 13.67;
  byte *ptr;   
  ptr = (byte*)&x;  //ptr holds beginning address of 4-byte memory space containing value of x 
  for (int i = 0, address = 0; i < 4; i++, address++, ptr++)
  {
    EEPROM.write(address, *ptr);
  }

4. All the codes of Step-3 can be replaced by the following two lines of codes:

float x = 13.67;
EEPROM.put(address, x);
3 Likes