2022-04-24 03:18 AM
2022-04-24 06:13 AM
you should use sprintf
char v[4];
sprintf(v,"%.2f",your_var);
then send var v on serial
2022-04-24 10:13 AM
Likely going to want more than 4 bytes to hold the string and NUL
Do you want to send the data in an ASCII form, or the form it is stored in memory?
For strings also fota() and dtoa() functions.
https://www.geeksforgeeks.org/convert-floating-point-number-string/
https://chromium.googlesource.com/native_client/nacl-newlib/+/master/newlib/libc/stdlib/dtoa.c
2022-04-25 06:06 AM
#include <stdio.h>
char buffer[200];
int i, j;
double fp;
char *s = "baltimore";
char c;
int main(void)
{
c = 'l';
i = 35;
fp = 1.7320508;
/* Format and print various data */
j = sprintf(buffer, "%s\n", s);
j += sprintf(buffer+j, "%c\n", c);
j += sprintf(buffer+j, "%d\n", i);
j += sprintf(buffer+j, "%f\n", fp);
printf("string:\n%s\ncharacter count = %d\n", buffer, j);
}
/********************* Output should be similar to: *************
string:
baltimore
l
35
1.732051
character count = 24 */