Type conversion not working? ESP32 Wroom

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 938
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Type conversion not working? ESP32 Wroom

Post by mnfisher »

I tested on an esp32 and it worked correctly...

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Type conversion not working? ESP32 Wroom

Post by mnfisher »

I used the UART instead of a LCD - for ease...
Type conv.fcfx
(19.81 KiB) Downloaded 57 times

MJU20
Posts: 237
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Type conversion not working? ESP32 Wroom

Post by MJU20 »

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?

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Type conversion not working? ESP32 Wroom

Post by mnfisher »

You need to add '.0' after one or both of the numbers - so 24744.0/244.0 would do the trick..

chipfryer27
Valued Contributor
Posts: 1110
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 278 times
Been thanked: 397 times

Re: Type conversion not working? ESP32 Wroom

Post by chipfryer27 »

Ah.... but did it smell like a Float..... you should sniff test anything that can vary :lol:

MJU20
Posts: 237
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Type conversion not working? ESP32 Wroom

Post by MJU20 »

I forgot to write that with the .0 it works!
I should have written that in my previous post. I'm sorry. :oops:

But then again, how is it that I should have known that a number is an INT?
(see: viewtopic.php?p=7593#p7593)

MJU20
Posts: 237
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Type conversion not working? ESP32 Wroom

Post by MJU20 »

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..
:(

chipfryer27
Valued Contributor
Posts: 1110
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 278 times
Been thanked: 397 times

Re: Type conversion not working? ESP32 Wroom

Post by chipfryer27 »

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

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Type conversion not working? ESP32 Wroom

Post by mnfisher »

Type conversion should work either way.

If you can post a sample/pm your code I'll take a look..

Martin

mnfisher
Valued Contributor
Posts: 938
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 502 times

Re: Type conversion not working? ESP32 Wroom

Post by mnfisher »

Here I stuff the values into a second TypeConversion - and display the result...

Seems to work okay..
Type conv.fcfx
(21.99 KiB) Downloaded 47 times
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

Post Reply