hiii every buddy ... im only trying to get afloat number whom im sending with xbee ... i need this number for math matical analysis after that /// so far im able to get the number into char array after that im using the ftoa func. so i can work with the number ... but im not using this func. probaply it returns 0 all the time ... so if any one can tell me what is the right thing to do here is my code :
#include <stdlib.h>
String readString;
void setup() {
Serial.begin(9600);
}
void loop() {
while (Serial.available()) {
delay(10);
char c = Serial.read(); //gets one byte from serial buffer
readString += c;} //makes the string readString
if (readString.length() >0) {
Serial.println(readString);
double n=0;
char carray[6];
readString.toCharArray(carray, sizeof(carray));
ftoa(carray,n,2);
Serial.println(carray);
readString="";
}
}
char *ftoa(char *a, double f, int precision)
{
long p[] = {0,10,100,1000,10000,100000,1000000,10000000,100000000};
char *ret = a;
long heiltal = (long)f;
itoa(heiltal, a, 10);
while (*a != '\0') a++;
*a++ = '.';
long desimal = abs((long)((f - heiltal) * p[precision]));
itoa(desimal, a, 10);
Serial.println(ret);
return ret;
}