This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Type casting integer to float ?

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

Parents Reply
  • From terminal  :

    <info> app: Float number: 0.000
                                                   

                                   
                                                  

    nfo> app: Float number V2:
                 

    Code : 

    	uint32_t int_value;
    	float float_val;
    	
           
        //float_val = *(float *)&int_value;	
        memcpy(&float_val, &int_value, sizeof(int_value));
    	  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);

Children
Related