Hello,
I came across this thread because I was trying to print floats and
couldn't. I tried the solution proposed
> One way to "print" a floating point number might be:
> printf("%d.%03d", fp, (fp - (int)fp) * 100);
> YMMV: note the issues with negative numbers and rounding errors.
but it wasn't working correctly. I found a snippet that seems to work,
so I leave it here.
------------
void printfFloat(float toBePrinted) {
uint32_t fi, f0, f1, f2;
char c;
float f = toBePrinted;
if (f<0){
c = '-'; f = -f;
} else {
c = ' ';
}
// integer portion.
fi = (uint32_t) f;
// decimal portion...get index for up to 3 decimal places.
f = f - ((float) fi);
f0 = f*10; f0 %= 10;
f1 = f*100; f1 %= 10;
f2 = f*1000; f2 %= 10;
printf("%c%ld.%d%d%d", c, fi, (uint8_t) f0, (uint8_t) f1,
(uint8_t) f2);
}
------------
Bernardo
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help