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
Calculatino problems
Moderator: Benj
-
- Posts: 101
- Joined: Tue Sep 01, 2015 9:37 pm
- Been thanked: 14 times
- Contact:
- 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
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.
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
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.
Instead what about doing this, assuming my brackets are correct.Var 1 = 1 (Byte)
Var 2 = 144 (Byte)
Var3 = (Var2 / 400) + (Var1 * 100 * 400 * 0.0016)
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
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 101
- Joined: Tue Sep 01, 2015 9:37 pm
- Been thanked: 14 times
- Contact:
Re: Calculatino problems
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel