3 years, 2 months ago.

Send float with Bluetooth not all values are sending

Hello when I send for example : float f = 0.123456789 On the other device I only receive 0.123457

The problem doesn't come from the other device. Beacause when I read the frames 6, 8 and 9 are missing.

Here my code


I have the same problem with : BT.printf(); BT.putc(); or BT.printf("%f", f);

1 Answer

3 years, 2 months ago.

Hi there,

You are only receiving the number "0.123457" because your tostr method is only converting the first 6 decimal places of your float number into a string. Try the following to get all 9 digits of your number:

double f = 0.123456789;
char buffer[32];
sprintf(buffer, "%.9lf", f);
string sf(buffer);

Please let me know if you have any questions!

- Jenny, team Mbed

If this solved your question, please make sure to click the "Thanks" link below!