Hard to come up with a Subject that will make sense...
Since sprintf() can't accept floats, I found this bit of code to convert an integer to a String and add the decimal. However I'm confused on how to actually use it. I'm still learning about functions and pointers, so the inputs to this function I don't understand.
Thread in question:
https://forum.arduino.cc/index.php?topic=44262.0
Say my code was like this:
float tempFloat = 123.45; // Test float value
int floatToInt;
char Output[10]; // for ftoa function
char buffer1[21]; // Needs to be 21 for LCD line width + null (LCD stuff truncated for example simplicity)
void setup() {}
void loop() {
floatToInt = (tempFloat * 100); // Convert float to int
Output = ftoa(???, ???, 2); // This is what I'm struggling with, inputs to the function
sprintf(buffer1, "T:%2sF", Output); // Format output buffer
Serial.println(buffer1); // Print output buffer
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);
return ret;
}