How to send Float values from one arduino to another

Hello

I want to send float values (having six digits after the decimal points) from one arduino to another arduino using Xbee S2...The float values are stored in an array and are transmitted one by one using Xbee in AT mode...I want to receive those values and store it in an array...After storing I want to print those values.If I do so I can get only two values after the decimal points.How to get all the values.

Please help me with the code.

Transmitter code

float transmit[3]={72.453444,83.345678,60}; //Values to be sent

void setup()
{
    Serial.begin(115200);
    Serial.write((uint8_t*)transmit, 3 * sizeof(float));
}
void loop()
{
}

Receiver’s Code:

float received[3];     //create an float array
int i;
void setup()
{
    Serial.begin(115200);
}
void loop()
{
    if (Serial.available() >= 3 * sizeof(float));
    {
        uint8_t *recv_bytes = (uint8_t*)transmit;
        for(i=0; i < 3 * sizeof(float); i++)
        {
            recv_bytes[i] = Serial.read();
        }
        Serial.println(received[0]);  
        Serial.println(received[1]);  
        Serial.println(received[2]);   
    }
}

Output:

77.12 
88.23 
60.00

Look up Serial.print() or println() in the Reference section, how to format floating numbers. You have to supply also the desired number of decimal places.

Your numbers have more digits than a float can represent.

Hello man,

your code has an error when i tried to downloaded, it say that transmit has not been declare and by other side, the variable received it is always empty.