FloatToString function problem

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

FloatToString function problem

Post by Mathy »

Hello!

I think there is a problem with the FloatToString function.
If I create a 4 bytes array to store a float number like 24.8, I am not able to send the right value by the rs232 sendstring macro.
My terminal only receive 3 bytes.
If I create a 5 bytes array, I receive wrong value (24.7)

Can you confirm that ?

Thank you for your time.

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: FloatToString function problem

Post by Jordy101091 »

Please can you post your program so I can have a look ad it.

regards jordy
the will to learn, should not be stopped by any price

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FloatToString function problem

Post by Mathy »

Hello Jordy and thank you for your help :)
Attachments
Flowcode1.fcfx
(6.05 KiB) Downloaded 250 times

User avatar
Jordy101091
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 25 times
Been thanked: 188 times
Contact:

Re: FloatToString function problem

Post by Jordy101091 »

There is something wrong with the FloatToString function.

When you are sending 24.8 "float to string converted" then in the console windows you can see that its sending the number 24.79 with is not correct.

To overcome this issue you while need to add 0.01 to 24.8 to send/receive 24.8 which is not the correct way to do it, but it works for now.
How ever if you increase the string array from 5 to 6 then with the above modification you will send/receive 24.809.

which tells me that Flowcode needs to fill the entire array with something so it decides to include a 9.

I came up with a work around the way this works is:
First determine how big the array is, this is done by overflowing the array with random numbers.
Then take this array and check its length (looking how many chars) with the function Length$().
Now we now how big your array is, in you case its "5".

Then based on that number we need to divide 1 by 10 to get the desired compensation value e.g. 0.1 / 0.01 / 0.001 and so on.
This number then gets added by the number you want to send.
This way you will send / receive the correct information.

I have only tested this in software / simulation so I don't know If it would work o you hardware.
Other wise it would be best to convert you float variable to a inerter and converted this back to a string and modify this string so it corresponds with the value you want to receive.

I hope this helps you out, its just a temporary fix :wink:
If not then tell me.

Regards Jordy
Attachments
Flowcode1.fcfx
(7.97 KiB) Downloaded 259 times
the will to learn, should not be stopped by any price

Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

Re: FloatToString function problem

Post by Mathy »

Hello Jordy and thank you for your help.

Is there a new release of Flowcode available ?
Because I have the 6.0.4.0 and Im not able to open your file.

I will try by myself with your explanation so don't worry about that.

Have a nice day,

Mathy

Post Reply