Dear Members,
I want to convert uint32_t to float, the code :
unsigned int dat = 2248; float float_val; float_val = (double)(dat); NRF_LOG_INFO( "float_val = %.3f\n", float_val );
It's returning nothing, what is missing here ?
Thanks
Dear Members,
I want to convert uint32_t to float, the code :
unsigned int dat = 2248; float float_val; float_val = (double)(dat); NRF_LOG_INFO( "float_val = %.3f\n", float_val );
It's returning nothing, what is missing here ?
Thanks
Hi,
There is a mistake in your code. your float_val variable is a float (32 bit), but you cast dat to a double (64 bit). So you should fix the fast so that you cast it to a float instead.
uint32_t int_value;
float float_val;
float_val = *(float *)&int_value;
or memcpy(&float_val, &int_val, size_of(int_value);
Hi Einar,
Thanks for the reply,
I will fix it and keep posted, thanks again
then NRF_LOG_INFO("Float number V2: %.2f",float_val); ?
Snipped :
unsigned int dat = 2248; float float_val = *(float *)&dat; NRF_LOG_INFO("Float number: "NRF_LOG_FLOAT_MARKER"\n\r",NRF_LOG_FLOAT(float_val)); NRF_LOG_INFO("Float number V2: %.2f",float_val);
I got 0.00 for float_val ??