transforming received bytes to int

I know i've asked similar questions in the past (atleast related to serial parsing), and there are lots of previous questions asked which i have read all i can find so please don't shoot me down,

but i'm trying to read in data of the form (34.4543,100.54930) (numbers are irrelevant) from the serial moniter and store the two values as floating variables.

I can read the data into a buffer that i can now do, its bringing back the data to a float in which i have trouble. From what ive found on the net i think i need too multiply the values by a factor (say a 1000) to bring them to a long (setting a limit on the allowed input number length), and use either the union function, or convert the Ascii to bytes, then multiply the preceeding value by 10, and add the next value similar to Messages TO Arduino from Serial Monitor- FA1smtoard.

Ive also read tutorials on sprintf() and atoi() but i'm just not sure one which i need too work.

this is one of the variations of my code which i know doesn't work, but ive made several attempts, and you can atleast see the basis of my code

float headingLat;
float headingLong;
boolean storeString;
int index_rf = 0;
byte buffer_rf[30];
  char startChar_rf = '(';
  char endChar_rf   = ')'; 
float lat;
int incomingbyte_rf;

union u_tag {
    byte b[30];
    long fval;
} u;




void setup() {
  // initialize serial communication:
  Serial.begin(9600);
 }

void loop() {
  while(Serial.available() > 0) {

  char incomingbyte_rf = Serial.read();
    if(incomingbyte_rf == startChar_rf){
    index_rf = 0;  
    storeString = true;
    }
    if(storeString){
    if(incomingbyte_rf==endChar_rf){
        buffer_rf[index_rf] = 0;
        storeString = false; 
                     
         Serial.println(buffer_rf[0]);
         Serial.println(buffer_rf[1]);
         Serial.println(buffer_rf[2]);
         Serial.println(buffer_rf[3]); //debugging, just to see if it prints the right order/right no's.
         Serial.println(buffer_rf[4]);
         Serial.println(buffer_rf[5]);
         //Might need ascii to binary converter here first?
u.b[0] = buffer_rf[1];
u.b[1] = buffer_rf[2];
u.b[2] = buffer_rf[3];
u.b[3] = buffer_rf[4];
lat = u.fval;
Serial.println(lat); 
    }       
  else{
   buffer_rf[index_rf++] = incomingbyte_rf;
   
  }

  }
  }
}

Thanks for any advice.

Ive also read tutorials on sprintf() and atoi() but i'm just not sure one which i need too work.

Then you should know that sprintf is how you convert a number to a string, and that it doesn't work for floats.

Since you want to convert a string to a number, sprintf is NOT what you want.

You should also be aware that atoi() is the ASCII (a) to (to) integer (i) conversion function.

Given this, can you guess the name of the ASCII (a) to (to) float (f) conversion function?

Thanks for the reply
yeah i had sort of ruled out sprintf and atoi, i just knew they were what i sort of wanted to do, but with different formats.

i had stumbled across atof() but i think i forgot about it when i started trying the union idea..
i just read its definition on Cplusplus and it seems like i could work, but anyideas how i could either bring each element of the buffer[1....5] or how ever big which represents each digit of the number , into one string? (understandably it doesnt seem atof() can handle the . in the string, so the input would have to be multiplied and divided to take that into account..

I'm getting the feeling this is a pretty simple thing to do, but i've just spent days on it and have seemed to confuse myself with all these different tutorials telling me how to do it, but I can't seem to modify them to fit my needs.. also,

Thanks again for your help PaulS!

Create a simple sketch to learn how to use strtok() and atof().

char numbers[] = "-14.7, 235.7, 89.887";

void setup()
{
   char *token1 = strtok(numbers, ",");
   float num1 = atof(token1);
   char *token2 = strtok(NULL, ","); // Keep parsing same array
   float num2 = atof(token2);
   char *token3 = strtok(NULL, ",");
   float num3 = atof(token3);
}

void loop() {}

Add Serial.begin() and Serial.print() statements to see what is in token1, token2, token3, num1, num2, and num3.

Then, apply to your situation.

The strtok function atof combo worked perfectly one i knew how to use it!

thanks so much for your help!

Just for the record, sprintf won't work with floats in the Arduino environment. Also, in addition to atof() there is atod() to convert a string to a double.