 # How to store decimal value in eeprom

hello all :) I need to store on eeprom a decimal value like 5000.I understand I can't put all this value on a single address since the maximum value is 255.My question is how can I store this value in eeporm?

If he value that you want to store is an int (integer data type 16 bits) you can ues the highByte and lowByte functions to split the int into 2 bytes. Store the bytes in consecutive locations.

By the same way as it is stored in RAM - float or double 4 bytes.

Can you send me an example code,plz? Because I am very new to Arduino.

Budvar10: By the same way as it is stored in RAM - float or double 4 bytes.

"Stored" used as an adjective but not as a verb. It can be stored (set) in RAM with a simple assignment statement. That isn't true of EEPROM.

(some as of yet undreamed of language will permit such things)

Sumyatmon, for examples, look at the EEPROM library examples. Have you looked at the functions mentioned in reply #1?

Sumyatmon:
Can you send me an example code,plz? Because I am very new to Arduino.

``````union {
float f;
byte arr;   // float is 4 bytes
} x;

x.f=3.14159265;

for (byte i=0; i<4; i++) {
byte b=x.arr[i];
// save byte b to EEPROM
}
``````

Also works in reverse: reading 4 bytes from EEPROM, putting them into the array ‘arr’ and then reading out the resulting float f.

This is not Arduino-spesific, it’s just C.

Corresponding example using int (which is 2 bytes)

``````union {
int value;
byte arr;
} x;

x.value=5000;
// save x.arr and x.arr to EEPROM
``````

Can I use this function?

unsigned int value=5000;

SaveToEEPROM(0,value);

Fine, but I thought you wanted a "decimal"

Is SaveToEEPROM is one of <EEPROM.h> instructions in Arduino? I don’t know that involves in Arduino IDE software .

aarg: "Stored" used as an adjective but not as a verb. It can be stored (set) in RAM with a simple assignment statement. That isn't true of EEPROM.

(some as of yet undreamed of language will permit such things)

Thank you sir for lesson but I am still not clear about right sentence. "As it is stored in the RAM."

@Sumyatmon Sorry for OT. Rupert answered almost all. Use EEPROM.write for example but int cannot be decimal.

KeithRB: Fine, but I thought you wanted a "decimal"

Sorry. My mistake!

I mean, for example, I want to store unsigned int 5000 like money amount in EEPROM.

You can use EEPROM.put to write any data type to internal eeprom. You can use EEPROM.get to retrieve the value from internal eeprom.

``````#include <EEPROM.h>

void setup()
{
Serial.begin(9600);

int i = 1024;
float f = 3.14;

int j;
float g;

EEPROM.put(0, i);
EEPROM.put(0 + sizeof(int), f);

EEPROM.get(0, j);
Serial.println(j, DEC);

EEPROM.get(0 + sizeof(int), g);
Serial.println(g, 3);

}

void loop()
{

}
``````