Calculatino problems

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

Moderator: Benj

Post Reply
kennethnilsen69
Posts: 101
Joined: Tue Sep 01, 2015 9:37 pm
Been thanked: 14 times
Contact:

Calculatino problems

Post by kennethnilsen69 »

I have a calculation I did not get.

Var 1 = 1 (Byte)
Var 2 = 144 (Byte)

Var3 is Int
calculation is:

Var3 = (Var2 / 400) + (Var1 * 100 * 400 * 0.0016)

This should be 1 but I get 0

then I think that the problem is maybe decimals.

so I try:
Var3 = ((Var2 * 100/400) + (Var1 * 100 * 400 * 0.0016)) / 100

but the answer is still 0 instead of 1

I need some help to understand this


Thanks
Kenneth

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Calculatino problems

Post by Benj »

Hi Kenneth,

I think the problem is that the variables you are storing into is an integer and the calculation may not be doing the order you require.
Var 1 = 1 (Byte)
Var 2 = 144 (Byte)
Var3 = (Var2 / 400) + (Var1 * 100 * 400 * 0.0016)
Instead what about doing this, assuming my brackets are correct.

Var3 = (Var2 / 400)
Var3 = Var3 + (((Var1 * 100) * 400) * 0.0016)

This works out as below so I assume my brackets are wrong for what you need.

Var3 = (144 / 400) = 0
Var3 = 0 + (40000 * 0.0016) = 64

kennethnilsen69
Posts: 101
Joined: Tue Sep 01, 2015 9:37 pm
Been thanked: 14 times
Contact:

Re: Calculatino problems

Post by kennethnilsen69 »

Thanks but I solved it by using Floating point and a str instead of Init

Var 1 = 1 (byte)
Var 2 = 144 (byte)

Var3 is Floating point
var4_str[4]
calculation is then:

Var3 = (Var2 / 400) + (Var1 * 100 * 400 * 0.0016)

Var4_str = FloatToString$ (Var3)

Then Var_str is 1.00 just as i want :-)

Thanks

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Calculatino problems

Post by Benj »

Great, glad it's working for you now.

Still not sure how your ending up with 1 when I get 64 but as long as it's doing what you expect then that's great.

Post Reply