 |
 |
|
|
|
|
|
| How do I multiply floating point values (decimals) in ROBOLAB 2.9? |
| (1 ) |
100%
0%
|
The multiply block does not preserve the floating point status of its input factors (the digits to the right of the decimal point).
For example, if you store the floating point number 1.68 in a container and then use the multiply container block to multiply it by 10, the resulting container value is 20 because 1.68 is rounded up to 2 before the computation occurs.
To multiply decimals, use the 'Evaluate Expression' and 'Fill Container w/ Variable' blocks from the container menu.
- Use the 'Evaluate Expression' block to declare variables as floating point numbers with decimal values. \n
- Then, use the 'Fill Container w/ Variable' block to type in the multiplication formula of the variables and store the result of that formula in a regular container. \n
- Note that as soon as you store that result in a regular container, it is rounded down into an integer. However, the floating point values were used for the calculation itself. (This means that, for example, if you declare floating point variables with values of 1.68 and 10, and you multiply them using a formula, the computation results in 16.8, but the integer 16 is stored in the container.

This program declares two floating point variables, convert and distance, and gives them values of 1.467 and 5, respectively. Then it uses the 'Fill Container w/Variable' block to fill the red container with the product of convert and distance. The product is automatically rounded down to an integer. Since 1.467*5 = 7.335, the number 7 is stored in the red container. Next, the program displays the number 7 on the RCX display, and then it waits for 7 rotation clicks (1/16th of a rotation).
KAB
|