Issue with Decimal Point Display When Dividing Decimal Numbers in Flowcode

Any bugs you encounter with Flowcode should be discussed here.
Post Reply
bazkhf
Posts: 7
http://meble-kuchenne.info.pl
Joined: Sun Jan 14, 2024 10:15 am
Has thanked: 1 time
Been thanked: 1 time

Issue with Decimal Point Display When Dividing Decimal Numbers in Flowcode

Post 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
Attachments
nodecimal.fcfx
(14.32 KiB) Downloaded 265 times

mnfisher
Valued Contributor
Posts: 1279
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 122 times
Been thanked: 643 times

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

Post 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.

bazkhf
Posts: 7
Joined: Sun Jan 14, 2024 10:15 am
Has thanked: 1 time
Been thanked: 1 time

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

Post 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.

mnfisher
Valued Contributor
Posts: 1279
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 122 times
Been thanked: 643 times

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

Post 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

Post Reply