Help with Mathematic Operation
TurnipTruck
Posts: 1,485
Greetings,
I am trying to do the following operations to arrive at a value for a timeline step:
1. Divide one integer by another integer resulting in a float with three decimal places
2. Multiply the float by 1000, resuling in an integer
I have tried several things including the format command, but cannot get it to work.
Any suggestions appreciated.
Thanks.
I am trying to do the following operations to arrive at a value for a timeline step:
1. Divide one integer by another integer resulting in a float with three decimal places
2. Multiply the float by 1000, resuling in an integer
I have tried several things including the format command, but cannot get it to work.
Any suggestions appreciated.
Thanks.
0
Comments
1. copy the integer value into a float variable and then do your divide.
float = integer
float = float / x
2. Do the math then copy the float value into a integer variable using type_Cast.
integer = type_cast(float * 1000);
Rather than fight the float, I just rewrote the routine to use integer math.
This has been tested to work with Duet Firmware...Do not know the problem Danny is talking about!
I am assuming TPVOL is an integer?
fVOL=(((TPVOL * 40) / 255) - 20)
If the metadata senses an integer type in the math, it will do integer math... This may have changed at one point for some reason or another. The math works correctly if no variables are used... It will do float math... But as soon as you add a variable where it can get metadata to determine what type of math to do...that is what it will do...
// Will do float math
fVOL=(((2 * 40) / 255) - 20)
// solution
fTemp = TPVOL
fVOL=(((fTemp * 40) / 255) - 20)
Now my color space conversions work! Very helpful, thanks a lot!