I am working with the C8051F580 using a custom board.
I use UART0 to communicate with TERATERM. 115200 bps
I am using printf to send characters to TERATERM
for decimal printing works fine: printf ("%d",(samples[i]*5)/100);
but if I change it to float it displays "???" : printf ("%3.6f",(samples[i]*5)/100);
"samples" is unsigned int
any suggestion will be appreciated
Thank you.
Fausto Bartra
That's not so much "funny" as it is the way C works, and always did: operations on integers yield integers, so if it's floating-point output you wanted, you have to transition to floating-point at some point in the computation.It may well be a generally better plan to not involve floats at all, though, and instead allow the output to come without that decimal separator:
printf("%9u", samples[i]*5);
because surely, whatever is at the receiving end of that output has an easier time converting to floating-point data formats than a small, FPU-less 8051 derivative.