8 years, 3 months ago.

how to convert double value to uint8_t value.

I'm new to mbed and its developing. I have a double value . That value i want to convert to uint8_t type array how do i do it.

My value -> double test=123.234 I want to convert to -> uint8_t convert[]={'1','2','3','.','2','3','4'};

And help is appreciated. Thank you

1 Answer

8 years, 3 months ago.

I assume you are converting double to ascii string??? If so, be careful with your size of convert[] as it must be large enough to take any values of test. For your example, a size of 8 works

uint_8 convert[8];
double test = 123.456;
sprintf(convert, "%7.3f", test);

Error: Argument of type "std::uint8_t *" is incompatible with parameter of type "char *" in "main.cpp", Line: 28, Col: 10

posted by hard rox rox 14 Sep 2016

Call convert a char, which is pretty much the same anyway.

Or alternatively explicitly cast it:

sprintf((char*)convert, "%7.3f", test);
posted by Erik - 14 Sep 2016