1 year, 8 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

/media/uploads/Daxmawale/capture.png

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

Comment on this question

1 Answer

1 year, 8 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);
printf(sf.c_str());

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!


You need to log in to post a question