cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Integer to float

Sax
Associate III

Hello everyone, can someone tell me why casting doesn't work. I want to convert int values of an array to float.

for (int i = 0; i<= adcBufferSize; i++)

{

adc_buffer_float[i] = (float)adc_buffer [i];

}

12 REPLIES 12

Show an example data set that's "Not Working"

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

 

Sax_1-1705741499741.png

 

Ok that seems to illustrate the input, it doesn't show the "not working" nor does it show or explain how the output is wrong or incorrect. 

What's the expectation and how does that differ from reality?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Aren't the float numbers supposed to look like this 4076.0 ; 4082.0 ; 3.0 ; 1.0 ?

One might hope the debugger would display that way.

Hard to tell from here how the array is actually defined.

You could do the conversion / ranging in a single step. Probably want to use 2048.0f there

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

Nope, debugger traditionally displays the float format as *(float*)( & variable ) rather than (float)variable. If you want the latter, use expressions.

 

Maybe you expect something new - but  : 946 (int) -> still 946 (float) , just could write as 946.0  ;

so debug shows correct your float, just without x.000 , if nothing fractional there.

 

AScha3_0-1705773463916.png

b= 2.6 , but for b= 3. 0 ->

AScha3_1-1705773522772.png

ok ?

If you feel a post has answered your question, please click "Accept as Solution".
Great, thank you very much for the feedback!

Great, thank you very much for the feedback!