C. Sengstock wrote:
Hi,
i want to convert a floating point number to a character array, because I
want to save the number in an NVSRAM which can be described as:
unsigned char RAM[size];
#include <stdio.h>
#include <float.h>
int main(void)
{
char s[BUFSIZ];
sprintf(s, "%.*g", DBL_DIG, 0.00000037);
printf("Here's one such string: %s\n", s);
sprintf(s, "%.*g", DBL_DIG, 0.00037);
printf(" here's another: %s\n", s);
sprintf(s, "%.*g", DBL_DIG, 0.37);
printf(" here's another: %s\n", s);
sprintf(s, "%.*g", DBL_DIG, 370.);
printf(" here's another: %s\n", s);
sprintf(s, "%.*g", DBL_DIG, 370000.);
printf(" here's another: %s\n", s);
sprintf(s, "%.*g", DBL_DIG, 370000000.);
printf(" here's another: %s\n", s);
sprintf(s, "%.*g", DBL_DIG, 370000000000.);
printf(" here's the last: %s\n", s);
return 0;
}
Here's one such string: 3.7e-07
here's another: 0.00037
here's another: 0.37
here's another: 370
here's another: 370000
here's another: 370000000
here's the last: 370000000000
--
Martin Ambuhl