# Floating point value into EEPROM

**URL:** <https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247>\
**Category:** Programming\
**Created:** [June 22, 2021, 10:00am UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247 "2021-06-22T10:00:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashu9314](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@ashu9314](https://forum.arduino.cc/u/ashu9314)\
**Post date:** [June 22, 2021, 10:00am UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/1 "2021-06-22T10:00:30Z")

</div>

hello All,  
i want to save multidimensional array (decimal value) into EEprom. it is working for integer but sometime i need to save decimal value too.  
can somebody help me in this regards??  
thanks in advance.

#include \<EEPROM.h\>  
#include \<SPI.h\>  
const int rows = 2;  
const int columns = 3;  
int array1[rows][columns] = { { 55.5, 2, 3 }, { 4, 5, 6 } };  
int addr;  
void setup () {  
Serial.begin(9600);

}  
void loop () {  
Serial.println ("Values in array1 by row are: ") ;

printArray(array1) ;

}

void printArray( const int a[][columns] ) {

for ( int i = 0; i \< 1; ++i ) {

```
  for ( int j = 0; j < 1; ++j )
  Serial.println (a[0][j] );
  addr= a[0][columns];

  EEPROM.update(addr, a[0][columns]);
  Serial.println (addr);

```

}  
}

---

<div class="post-metadata">

**Author:** ![anon35827816](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@anon35827816](https://forum.arduino.cc/u/anon35827816)\
**Post date:** [June 22, 2021, 10:02am UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/2 "2021-06-22T10:02:59Z")

</div>

An obvious solution to this is to realize that a float value in Arduino is basically just a memory area of 4 bytes, which you can store one by one in EEPROM. When retrieving them, you do the opposite.

So effectively you would have a routine that reads each individual byte from the float value (regardless of what the value of the float looks like), and a routine that reads them back from EEPROM for retrieval.

---

<div class="post-metadata">

**Author:** ![ashu9314](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@ashu9314](https://forum.arduino.cc/u/ashu9314)\
**Post date:** [June 22, 2021, 12:33pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/3 "2021-06-22T12:33:02Z")

</div>

is it work if i use double command. double command has 8 bytes.

---

<div class="post-metadata">

**Author:** ![Ballscrewbob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ballscrewbob/32/950458_2.png) [@Ballscrewbob](https://forum.arduino.cc/u/Ballscrewbob)\
**Post date:** [June 22, 2021, 1:24pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/4 "2021-06-22T13:24:23Z")

</div>

Your post was **MOVED** to its current location as it is more suitable.

Could you also take a few moments to [Learn How To Use The Forum](https://forum.arduino.cc/index.php?topic=710766.0).

Other general [help and troubleshooting advice can be found here.](https://support.arduino.cc/hc/en-us)  
It will help you get the best out of the forum in the future.

---

<div class="post-metadata">

**Author:** ![Koepel](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/koepel/32/637546_2.png) [@Koepel](https://forum.arduino.cc/u/Koepel)\
**Post date:** [June 22, 2021, 1:32pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/5 "2021-06-22T13:32:26Z")

</div>

> [@ashu9314](#):
>
> `int array1[rows][columns] = {{ 55.5, 2, 3 }, { 4, 5, 6 }};`

Where do you think that "55.5" floating point number is going ?  
Spoiler: Into thin air. Only the whole number of "55" is to heavy to fly away and that get stored in the integer.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [June 22, 2021, 6:15pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/6 "2021-06-22T18:15:17Z")

</div>

Is there any reason not to use EEPROM.put() and EEPROM.get() to do what you want ?

```cpp
#include <EEPROM.h>

float putArray[3][3] =
{
  {1, 2, 3},
  {1001, 1002, 1003},
  {2001, 2002, 2003}
};
float getArray[3][3];

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  EEPROM.put(0, putArray);
  EEPROM.get(0, getArray);
  for (int row = 0; row < 3; row++)
  {
    for (int col = 0; col < 3; col++)
    {
      Serial.print(getArray[row][col],2);
      Serial.print(",");
    }
    Serial.println();
  }
}

void loop()
{
}
```

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [June 22, 2021, 6:25pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/7 "2021-06-22T18:25:18Z")

</div>

> [@ashu9314](#):
>
> is it work if i use double command. double command has 8 bytes.

What processor are you using? In Arduino, double is the same as float, 4 bytes.

---

<div class="post-metadata">

**Author:** ![ashu9314](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@ashu9314](https://forum.arduino.cc/u/ashu9314)\
**Post date:** [June 24, 2021, 6:43am UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/8 "2021-06-24T06:43:50Z")

</div>

i am using Arduino Due.

---

<div class="post-metadata">

**Author:** ![ashu9314](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@ashu9314](https://forum.arduino.cc/u/ashu9314)\
**Post date:** [June 24, 2021, 6:57am UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/9 "2021-06-24T06:57:13Z")

</div>

I am sorry, i am beginner in programming and trying hard to learn it.  
It is just an example. I am going to use array to store 3 different sensor values and every column is specify for one sensor value.  
could you please help me to figure it out how can i update Row values for Sensor 1.  
i am comparing the two output of sensor on a different time (t1= 34m3, t2= 55.3m3) and if t1 is greater or equals to t2, t1 value shall go to a[R1][C1] and t2 value shall store to a[R2][C1].

---

<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:** [June 28, 2021, 3:27pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/10 "2021-06-28T15:27:14Z")

</div>

You have three sensors and assume that these are S1, S2, and S3. What types of sensors are they? Does each sensor produce one output? What is the range of the output of S1 in floating point format (For example)?

Note that:  
In Arduino UNO, NANO, MEGA and DUE, **float** allocates 4-bte memory space to hold floating point number of binary32 standard.

In Arduino DUE, **double** allocates 8-bte memory space to hold floating point number of binary64 standard.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 26, 2021, 3:27pm UTC](https://forum.arduino.cc/t/floating-point-value-into-eeprom/877247/11 "2021-10-26T15:27:49Z")

</div>

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
