Matrix

Rounding

16th June 2024
Math
Math
Notes
Last updated:15th July 2024
2 Minutes
350 Words

Rounding or rounding off means replacing a number with an approximate value that has a shorter, simpler, or more explicit representation 1.

Rounding Rules

  1. Less than halfway: round down (e.g., 53 \(\rightarrow\) 50).
  2. More than halfway: round up (e.g., 39 \(\rightarrow\) 40 ).
  3. Exactly halfway: round up (e.g., 35 \(\rightarrow\) 40).

Algorithm

To round an integer to the nearest multiple of 10 (or 100, 1000, etc.), follow these steps:

Determine the Nearest Multiples

  • Identify the previous multiple of 10 (or 100, 1000, etc.).
  • Identify the next multiple of 10 (or 100, 1000, etc.).

Calculate the midpoint

Find the midpoint between the previous and next multiple.
For rounding to the nearest 10, this midpoint is the previous multiple + 5

Apply Rounding Rules

  • Less than Midpoint: If the number is less than the midpoint, round down to the previous multiple.
  • Greater than Midpoint: If the number is greater than the midpoint, round up to the next multiple.
  • Exactly Midpoint: If the number is exactly at the midpoint, round up to the next multiple.

Example: Rounding the number 12

Determine the nearest multiples

  • The previous multiple of 10 before 12 is \(10\) .
  • The next multiple of 10 after 12 is \(20\) .

Calculate the midpoint The midpoint between \(10\) and \(20\) is calculate as:

$$ \text{midpoint} = \frac{10 + 20}{2} = 15 $$

Apply rounding rules Since 12 is less than the midpoint (15), we round 12 down to the previous multiple of 10, which is 10.

So, the number 12 rounds to 10 when rounded to the nearest multiple of 10.

Python codes

1
def round_to_nearest_ten(number):
2
# Find the previous and next multiples of 10
3
lower_multiple = (number // 10) * 10
4
upper_multiple = lower_multiple + 10
5
6
# Calculate the midpoint
7
midpoint = (lower_multiple + upper_multiple) / 2
8
9
# Determine and return the rounded result
10
if number < midpoint:
11
return lower_multiple
12
else:
13
return upper_multiple
14
15
# Test
6 collapsed lines
16
test_numbers = [3, 7, 12, 25, 37, 48, 55, 68, 73, 86, 92]
17
rounded_numbers = [round_to_nearest_ten(num) for num in test_numbers]
18
19
# Print results
20
for num, rounded in zip(test_numbers, rounded_numbers):
21
print(f"{num} rounds to the nearest multiple of 10 as {rounded}")

Reference

  • Engineering Mathematics — K.A.STROUD

Footnotes

  1. “Rounding or rounding off means replacing a number with an approximate value that has a shorter, simpler, or more explicit representation.” — Wikipedia.

Article title:Rounding
Article author:Matrix Chan
Release time:16th June 2024