Page 1 of 1

Issue with Decimal Point Display When Dividing Decimal Numbers in Flowcode

Posted: Tue Aug 13, 2024 12:00 pm
by bazkhf
Hello Flowcode Community,

I have been working on a project using Flowcode and encountered an issue related to displaying decimal numbers. I tried to divide the number 5 by 2 to get the result 2.5, but the result always came out as 2 across all variable types I used (such as INT, UINT, LONG, ULONG, and FLOAT). When using the BOOL variable type, the result was 0, which is expected given the nature of BOOL variables.

However, my main issue is with the other variables, as I was unable to get the decimal point in the result, even when using the FLOAT variable type. The result was always 2 with no decimal part, despite expecting to see the number 2.5.

I have not yet used the STRING variable type, but I have tried all other types and was unable to obtain the desired result with a decimal point.

I have included a screenshot of my Flowcode program and the Flowcode file that contains an LCD screen and the code which performs the division of 5 by 2 to verify that I was unable to output the result with a decimal point.

I would like to understand why the decimal point is not appearing in the results, even though I am using the appropriate variable types. Is there something I might have overlooked?

Thank you in advance for your assistance.
Image

Re: Issue with Decimal Point Display When Dividing Decimal Numbers in Flowcode

Posted: Tue Aug 13, 2024 12:09 pm
by mnfisher
You need to force floating point maths by making one of the values a fp value.

5.0 / 2.0 would do it.

5 and 2 will be treated as integers until assigned to the result.

Re: Issue with Decimal Point Display When Dividing Decimal Numbers in Flowcode

Posted: Sat Aug 17, 2024 6:52 am
by bazkhf
mnfisher wrote:
Tue Aug 13, 2024 12:09 pm
You need to force floating point maths by making one of the values a fp value.

5.0 / 2.0 would do it.

5 and 2 will be treated as integers until assigned to the result.

I was about to give up on trying to solve this problem, but thanks to your valuable help, I regained hope. Thank you for your support and encouragement.

Re: Issue with Decimal Point Display When Dividing Decimal Numbers in Flowcode

Posted: Sat Aug 17, 2024 8:55 am
by mnfisher
Glad you are going again.

The code defaults to integer maths because it is much simpler and quicker - the code will also need a lot less space (which is often at a premium on MCUs)

There is a lot of information for Flowcode (see flowcode.co.uk/support) - and also an active and friendly support forum. So if you are stumped it's always worth asking.

Martin