Lego EV3 Programming Round Block Title

Lego MINDSTORMS EV3: Round Block In Detail

In Lego Mindstorms by Glenn TurnbullLeave a Comment

In this post we will cover the Round programming block used within the Lego MINDSTORMS EV3 programming software. We will cover all the available options and also provide a step by step example program.

What Is the Round Block?

The EV3 Round block depending on it’s mode will convert a decimal value into an integer value (i.e. A whole number) or truncate a decimal at a specific decimal place. If for instance you have the decimal 1.54 and you wish to round this number up to 2 or down to 1, this is where this block is useful.

Lego EV3 Programming Round Block

What are the EV3 Round Block Modes?

The Round block has four modes and each of these modes are outlined below.

To Nearest Mode

The Rounding block’s “To Nearest” mode is the default and will use standard rounding rules to round the number either up or down. The “standard rounding rules” will round anything .5 or above to the next integer and .4 and below down to the current integer.

Lego EV3 Programming Round Block - To Nearest Mode

The table below gives some examples of “To Nearest” rounding:

Input Output
1.23 1
1.09 1
1.51 2
1.87 2
0.7 1
0.4 0

Round Up Mode

The Rounding block’s Round up mode will always round the input decimal up if there is a decimal value over 0, i.e. If the input is 1.1 it will round to 2 or 1.02 it will round to 2.

Lego EV3 Programming Round Block - Round Up Mode

The table below gives some examples of Round Up rounding:

Input Output
1.23 2
1.09 2
1.51 2
1.87 2
0.7 1
0.4 1

Round Down Mode

The Rounding block’s Round Down mode will always round the input decimal down if there is a decimal value over 0, i.e. If the input is 2.8 it will round to 2 or 3.9 will round to 3.

Lego EV3 Programming Round Block - Round Down Mode

The table below gives some examples of Round Down rounding:

Input Output
1.23 1
1.09 1
1.51 1
1.87 1
0.7 0
0.4 0

Truncate Mode

The Rounding block’s Truncate mode will funnily enough not do any rounding at all. As the name suggests it will remove any decimal portion of the input number after the specified decimal place. In this mode the Rounding block has an extra input named “Number of Decimals” and this is used to specify the number of decimals to keep.

Lego EV3 Programming Round Block - Truncate Mode

The table below gives some examples of Truncate mode:

Input Number of Decimals Output
1.23 1 1.1
1.09 0 1
1.51 1 1.5
1.8776 2 1.87
0.7 0 0
0.4332 3 0.433

How Many Decimals Does the EV3 Round Block Support?

The input number on the round block supports up to 6 decimal places. In Truncate mode the maximum Number of Decimals input value is 4, which means the maximum number of decimal places supported in the output is 4.

How to use the Round Block

The Lego EV3 Round programming block has 1 input and 1 output for all modes other than Truncate. As mentioned above, the Truncate mode uses an additional input name Number of Decimals to decide where to truncate the decimal number.

The input can be either wired from another block or hardcoded at the time of writing the program (same goes for the Number of Decimals input).

The example below will round 4.75 (input) to the nearest decimal value and output it to the Lego EV3 Brick display for 3 seconds.

Lego EV3 Programming Round Block Example

EV3 Round Block Example Program: Three Decimal Counter

In this Round block example program we’ll count out 10 seconds with up to 3 decimal places on the EV3 Brick’s display. We’ll use another rounding block to exit the loop after 10 seconds.

Program Logic:

  1. Set and start a timer
  2. Display the timer’s output (up to 3 decimal places) on the EV3 Display
  3. Round the timer’s output down and exit if it’s greater than or equal to 10.

Lets get started:

  1. Loop the program
    • Drag and drop an orange Loop block next to the Start block
      • Set its mode to Logic
Lego EV3 Programming Round Block Example Program - Step 1
  1. Set up the timer and output the value with 3 decimal places
    • Drag and drop an yellow Timer block inside of the Loop
      • Leave it’s mode at Measure | Time Indicator
    • Drag and drop a red Round block next to the Timer block
      • Set its mode to Truncate
      • Set the Number Of Decimals input to 3
      • Wire the Timer block’s output into the Input
    • Drag and drop a green Display block next to the Round block
      • Set its mode to Text | Pixels
      • Set Text to Wired
      • Wire the output of the Round block into the Display block
Lego EV3 Programming Round Block Example Program - Step 2
  1. Exit the program when the timer reaches 10 seconds
    • Drag and drop a red Round block next to the display block
      • Set its mode to Round Down
      • Wire the output from the Timer block into the input
    • Drag and drop a red Compare block next to the Round block
      • Set its mode to Greater Than Or Equal To
      • Wire the output from the Round block into the a value
      • Wire the Output into the Loop
Lego EV3 Programming Round Block Example Program - Step 3

That’s it! Hit the download and play button to test your program.

How would you change the output of the time on the display to 2 decimal places?

We hope you enjoyed this deep dive post into the Lego MINDSTORMS EV3 Round programming block. Feel free to leave a comment if you have any questions or have a suggestion for a future post.

Leave a Comment