Convert Integer to float
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 12:43 AM - edited ‎2024-01-20 12:44 AM
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];
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 12:55 AM
Show an example data set that's "Not Working"
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 1:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 1:17 AM - edited ‎2024-01-20 1:18 AM
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?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 1:53 AM
Aren't the float numbers supposed to look like this 4076.0 ; 4082.0 ; 3.0 ; 1.0 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 9:00 AM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 9:39 AM - edited ‎2024-01-20 10:36 AM
Nope, debugger traditionally displays the float format as *(float*)( & variable ) rather than (float)variable. If you want the latter, use expressions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-20 9:59 AM
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.
b= 2.6 , but for b= 3. 0 ->
ok ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-21 9:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-21 9:43 AM
Great, thank you very much for the feedback!
