# How to write float value in EEPROM

**URL:** <https://forum.arduino.cc/t/how-to-write-float-value-in-eeprom/896011>\
**Category:** Programming\
**Created:** [August 16, 2021, 8:41am UTC](https://forum.arduino.cc/t/how-to-write-float-value-in-eeprom/896011 "2021-08-16T08:41:05Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [August 16, 2021, 9:54am UTC](https://forum.arduino.cc/t/how-to-write-float-value-in-eeprom/896011/4 "2021-08-16T09:54:56Z")

</div>

> [@ashish\_senger](#):
>
> It worked out.

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](https://europe1.discourse-cdn.com/arduino/original/4X/d/1/c/d1cc04432119251013e6b7a3f0700c8028a724b0.png)  
Figure-1:

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

```arduino
  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:

```arduino
float x = 13.67;
EEPROM.put(address, x);

```

---

_[View the full topic](https://forum.arduino.cc/t/how-to-write-float-value-in-eeprom/896011)._
