Type conversion not working? ESP32 Wroom
-
- Valued Contributor
- Posts: 991
- http://meble-kuchenne.info.pl
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: Type conversion not working? ESP32 Wroom
This will be one of my greatest mystery's ever.
This is almost 1 on 1 the same as what I use in the other (larger) project.
I'm sure that the Float I'm trying to chop into bytes is a Float because I use it several times in the chart.
It always acts as a float, looks like a Float, tastes like a Float so I'm pretty sure it's a.. Float.
But in this other chart it looks like the conversion is not working.
So now I will try this somewhat further in this (example)chart and try to copy it into the larger project.
Again, thanks for your support.
Just for the sake of learning: how should I know that "24744/244" is stored as an INT where I ask to store it into a Float?
Is it I should have learned? Is this written somewhere? Is it that is convention in programming?
This is almost 1 on 1 the same as what I use in the other (larger) project.
I'm sure that the Float I'm trying to chop into bytes is a Float because I use it several times in the chart.
It always acts as a float, looks like a Float, tastes like a Float so I'm pretty sure it's a.. Float.
But in this other chart it looks like the conversion is not working.
So now I will try this somewhat further in this (example)chart and try to copy it into the larger project.
Again, thanks for your support.
Just for the sake of learning: how should I know that "24744/244" is stored as an INT where I ask to store it into a Float?
Is it I should have learned? Is this written somewhere? Is it that is convention in programming?
-
- Valued Contributor
- Posts: 1186
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 289 times
- Been thanked: 417 times
Re: Type conversion not working? ESP32 Wroom
Ah.... but did it smell like a Float..... you should sniff test anything that can vary
Re: Type conversion not working? ESP32 Wroom
I forgot to write that with the .0 it works!
I should have written that in my previous post. I'm sorry.
But then again, how is it that I should have known that a number is an INT?
(see: viewtopic.php?p=7593#p7593)
I should have written that in my previous post. I'm sorry.
But then again, how is it that I should have known that a number is an INT?
(see: viewtopic.php?p=7593#p7593)
Re: Type conversion not working? ESP32 Wroom
This is awkward...
The versions that have passed here all worked after testing.
Now I use the same code in the original file and it refuses to work..
Don't get it.
The version I'm working on has a Float that doesn't contain a value when I start so I give it an initial value of 10.0
Then I write "dummy" bytes to the type conversion (set bytes) and convert them in the float.
This always returns a 0.00 for the Float. Why?
I need to remove all non needed code to post (again) an example.. will take a while..
The versions that have passed here all worked after testing.
Now I use the same code in the original file and it refuses to work..
Don't get it.
The version I'm working on has a Float that doesn't contain a value when I start so I give it an initial value of 10.0
Then I write "dummy" bytes to the type conversion (set bytes) and convert them in the float.
This always returns a 0.00 for the Float. Why?
I need to remove all non needed code to post (again) an example.. will take a while..
-
- Valued Contributor
- Posts: 1186
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 289 times
- Been thanked: 417 times
Re: Type conversion not working? ESP32 Wroom
Hi
Only thing I can think on is to double check that the "dummy bytes" are actually bytes. These must be bytes and not integers etc.
Regards
Only thing I can think on is to double check that the "dummy bytes" are actually bytes. These must be bytes and not integers etc.
Regards
-
- Valued Contributor
- Posts: 991
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: Type conversion not working? ESP32 Wroom
Here I stuff the values into a second TypeConversion - and display the result...
Seems to work okay..
Note - one source of problems is that some values don't have an 'exact' representation as a float - so 3.000 might be 2.9999999 or 3.0000001 (probably not 3.0 - just an example of what happens) due to limitations in the float format (which is why for banking apps - values are stored as fixed point (2 integer) values)
So for comparisons - it is best to check a range (If x /y = z may not give the result you want - might need to do if (result > z - delta) && (result < z + delta))
Martin
Seems to work okay..
Note - one source of problems is that some values don't have an 'exact' representation as a float - so 3.000 might be 2.9999999 or 3.0000001 (probably not 3.0 - just an example of what happens) due to limitations in the float format (which is why for banking apps - values are stored as fixed point (2 integer) values)
So for comparisons - it is best to check a range (If x /y = z may not give the result you want - might need to do if (result > z - delta) && (result < z + delta))
Martin