void Float2Ascii (float x, unsigned char *str,char precision)
{
// converts a floating point number to an ascii string
// version limitée à 5 decimales maximum
// x is stored into str, which should be at least 30 chars long
int ie, i, k, ndig;
double y;
if (precision>=5) precision=5; else precision++;
ndig = precision;
ie = 0;
// if x negative, write minus and reverse
if ( x < 0.00000)
{
*str++ = '-';
x = -x;
}
// put x in range 1 <= x < 10
if (x > 0.000000) while (x < 1.000000)
{
x *= 10.000; // a la place de =*
ie--;
}
while (x >= 10.0000)
{
x = x/10.0000;
ie++;
}
// in f format, number of digits is related to size
ndig += ie; // a la place de =+
//round. x is between 1 and 10 and ndig will be printed to
// right of decimal point so rounding is ...
for (y = i = 1; i < ndig; i++)
y = y/10.0000;
x += y/2.0000;
if (x >= 10.0000) {x = 1.0000; ie++;}
if (ie<0)
{
*str++ = '0'; *str++ = '.';
if (ndig < 0) ie = ie-ndig;
for (i = -1; i > ie; i--) *str++ = '0';
}
for (i=0; i < ndig; i++)
{
k = x;
*str++ = k + '0';
if (i == ie ) *str++ = '.';
x -= (y=k);
x *= 10.0000;
}
*str = '\0';
}