Below I try to set the format specifier, but I want to do it differently every time I call the function. The point is to print a float Data_Ave. In one instance, I want the% 2.3f specifier, and so I will pass the function a 2 for sig_figs_before and 3 for sig_figs_after. In the following case, I want% 1.4f, so I would pass these ints.
char * Send_Data(float Data[10], const char* SUBJECT_SEND_NAME, char *Data_Backup, int sig_figs_before, int sig_figs_after)
{
float Data_Ave = ((Data[0] + Data[1] + Data[2] + Data[3] + Data[4] +
Data[5] + Data[6] + Data[7] + Data[8] + Data[9])/10);
sprintf(msgBody,"%%i.%if, ", before_decimal, after_decimal, Data_Ave);
...
}
I'm sure this will not work, so I decided to split the float into two ints and print them like this:
sprintf(msgBody,"%i.%i, ", int_value, decimal_value);
But I do not know how to split the float correctly. Any suggestions?
source
share