Chapterبەش 2 · Lectureوانە 2.4

Rounding and Decimal Placesنزیککردنەوە و خانە دەییەکان

How to round by hand with the cut-line method, what to do with an exact 5, this course's 4-decimal rule, why rounded numbers do not always add up, how rounding differs from truncation, floor and ceiling, and why Python's round() gives 2 for 2.5 and 2.67 for 2.675.

چۆن بە ڕێگای هێڵی بڕین بە دەست نزیک بکەیتەوە، لەگەڵ 5ـێکی ڕێک چی بکەیت، یاسای ئەم کۆرسە بۆ 4 ، بۆچی ژمارە نزیککراوەکان هەمیشە ڕێک کۆ نابنەوە، چ جیاوازییەکی لەگەڵ ، و هەیە و بۆچی round()ـی Python بۆ ⁦2.5⁩ دەڵێت 2 و بۆ ⁦2.675⁩ دەڵێت ⁦2.67⁩.

11 min read12 خولەک خوێندنەوە · 13 stepsهەنگاو

What you will learnچی فێر دەبیت

  • Round a number to a given number of decimal places with the cut-line method.
  • Handle the half-way case and carries correctly.
  • Explain rounding error and why you round only once, at the end.
  • Choose between rounding, truncation, floor and ceiling.
  • Predict what Python's round() does and round by the school rule with the decimal module.
  • ژمارەیەک بە ڕێگای هێڵی بڕین نزیک بکەیتەوە بۆ ئەو ژمارەیەی کە داوا کراوە.
  • حاڵەتی نیوەی ڕێگا و گواستنەوە بە دروستی چارەسەر بکەیت.
  • ڕوون بکەیتەوە و بۆچی تەنها یەک جار و لە کۆتاییدا نزیک دەکەیتەوە.
  • لە نێوان ، ، و هەڵبژێریت.
  • پێشبینی بکەیت round()ـی Python چی دەکات و بە decimal بە یاسای قوتابخانە نزیک بکەیتەوە.

Why we roundبۆچی نزیک دەکەینەوە

Many answers in statistics never end: 3019=1.578947…\frac{30}{19} = 1.578947\ldots, 7=2.645751…\sqrt7 = 2.645751\ldots, log⁡11=1.041392…\log 11 = 1.041392\ldots. Nobody can write all the digits, and nobody needs them. So we keep a fixed number of digits after the decimal point and replace the number with the closest shorter number. This is rounding.

زۆر وەڵام لە کۆتاییان نایەت: 3019=1.578947…\frac{30}{19} = 1.578947\ldots، 7=2.645751…\sqrt7 = 2.645751\ldots، log⁡11=1.041392…\log 11 = 1.041392\ldots. کەس ناتوانێت هەموو ژمارەکان بنووسێت و کەسیش پێویستی پێیان نییە. بۆیە ژمارەیەکی دیاریکراو لە دوای دەهێڵینەوە و ژمارەکە بە نزیکترین ژمارەی کورتتر دەگۆڕین. ئەمە .

Definitionپێناسە

Replacing a number with a shorter, close value, for example keeping only two : look at the next digit; 5 or more rounds up.

گۆڕینی ژمارەیەکە بە نرخێکی کورتتر و نزیک، بۆ نموونە هێشتنەوەی تەنها دوو : سەیری ژمارەی دواتر بکە؛ 5 یان زیاتر بەرەو سەرەوە دەبات.

Definitionپێناسە

A position of a digit after the . In 8.736 the digits 7, 3 and 6 are in the first, second and third decimal places.

شوێنی ژمارەیەکە لە دوای . لە ⁦8.736⁩دا ژمارەکانی 7 و 3 و 6 لە خانەی دەیی یەکەم و دووەم و سێیەمدان.

Quick checkپشکنینی خێراIn 8.736, which digit is in the second decimal place?لە ژمارەی ⁦8.736⁩ـدا کام ژمارە لە دووەم ؟

Rounding by hand: the cut-line methodنزیککردنەوە بە دەست: ڕێگای هێڵی بڕین

The course notes round 8.736 to two decimal places with a simple picture: a line that cuts the number.

تێبینییەکانی کۆرسەکە ⁦8.736⁩ بە وێنەیەکی سادە بۆ دوو نزیک دەکەنەوە: هێڵێک کە ژمارەکە دەبڕێت.

8.736 to two decimal places⁦8.736⁩ بۆ دوو خانەی دەیی
  1. Draw the cut lineهێڵی بڕین بکێشە

    Keep two decimal places, so draw a line after the second digit after the point: 8.73 ∣ 68.73\,|\,6.

    دوو دەهێڵینەوە، بۆیە لە دوای دووەم ژمارەی دوای خاڵەکە هێڵێک بکێشە: 8.73 ∣ 68.73\,|\,6.

  2. Look at one digit onlyتەنها سەیری یەک ژمارە بکە

    Look at the first digit after the line: 6. Ignore any digits after it.

    سەیری یەکەم ژمارەی دوای هێڵەکە بکە: 6. گوێ مەدە بە ژمارەکانی دوای ئەو.

  3. Decideبڕیار بدە

    6 is 5 or more, so round up: add 1 to the last kept digit, 73 becomes 74. (With 0–4 you keep the digits as they are.)

    6 پێنج یان زیاترە، بۆیە بەرەو سەرەوە: 1 بخەرە سەر دوایین ژمارەی هێڵراوە، ⁦73⁩ دەبێتە ⁦74⁩. (بە ⁦0–4⁩ ژمارەکان وەک خۆیان دەهێڵیتەوە.)

  4. Drop the restئەوانی تر فڕێ بدە

    Everything after the line goes. Answer: 8.74.

    هەموو شتێکی دوای هێڵەکە لادەبرێت. وەڵام: ⁦8.74⁩.

The number 8.736 written in large digits with labels: 8 is ones, 7 is the first decimal place, 3 the second, 6 the third. A dashed line cuts between 3 and 6. The part 8.73 is kept; the first dropped digit 6 is highlighted with the note 6 ≥ 5, so round up. An arrow leads to the answer 8.74, with 73 + 1 = 74 under it.ژمارەی 8.736 بە ژمارەی گەورە لەگەڵ ناوی شوێنەکان: 8 یەکانە، 7 خانەی دەیی یەکەمە، 3 دووەمە و 6 سێیەمە. هێڵێکی پچڕپچڕ لە نێوان 3 و 6دا دەیبڕێت. بەشی 8.73 دەمێنێتەوە؛ یەکەم ژمارەی فڕێدراو 6 ڕەنگ کراوە لەگەڵ تێبینیی 6 ≥ 5، بۆیە بەرەو سەرەوە. تیرێک دەچێت بۆ وەڵامی 8.74 و لە ژێریەوە 73 + 1 = 74 نووسراوە.
Only the first digit after the cut decides.تەنها یەکەم ژمارەی دوای هێڵەکە بڕیار دەدات.CêIT

Why it works: 8.736 lies between 8.73 and 8.74. It is 0.006 away from 8.73 but only 0.004 away from 8.74, so 8.74 is the closest number with two decimal places. The cut-line rule is a quick way to find the closest one.

بۆچی کار دەکات: ⁦8.736⁩ لە نێوان ⁦8.73⁩ و ⁦8.74⁩دایە. ⁦0.006⁩ لە ⁦8.73⁩ دوورە، بەڵام تەنها ⁦0.004⁩ لە ⁦8.74⁩ دوورە، بۆیە ⁦8.74⁩ نزیکترین ژمارەیە کە دوو هەبێت. یاسای هێڵی بڕین ڕێگایەکی خێرایە بۆ دۆزینەوەی نزیکترینیان.

Quick checkپشکنینی خێراRound 3.14159 to two decimal places.⁦3.14159⁩ بۆ دوو نزیک بکەرەوە.

How to Round Decimals Places (2026/27 exams)Cognito · Englishئینگلیزی · 176K viewsبینین · 2.8K likesلایک

Rounding to decimal places: find the last digit you keep, look at the next "decider" digit, round down or up, and keep needed zeros.

بۆ چەند : دوایین کە دەیهێڵیتەوە بدۆزەرەوە، سەیری دواتر («بڕیاردەر») بکە، بۆ خوارەوە یان سەرەوە نزیکی بکەرەوە و سفرە پێویستەکان بهێڵەوە.

Chapters: 0:27 the last digit and the decider, 0:55 round down or up, 3:35 why trailing zeros matter.

بەشەکان: ⁦0:27⁩ دوایین و «بڕیاردەر»، ⁦0:55⁩ بۆ خوارەوە یان سەرەوە، ⁦3:35⁩ بۆچی سفرەکانی کۆتایی گرنگن.

Exactly 5: the half-way caseڕێک 5: نیوەی ڕێگا

If the first dropped digit is 0, 1, 2, 3 or 4, keep the number. If it is 5, 6, 7, 8 or 9, round up. A 5 with nothing after it is a special case: the number is exactly half-way, for example 8.735 between 8.73 and 8.74. Neither neighbour is closer, so we need a rule. The school rule says: round half up.

ئەگەر یەکەم ژمارەی فڕێدراو 0، 1، 2، 3 یان 4 بوو، ژمارەکە وەک خۆی بهێڵەرەوە. ئەگەر 5، 6، 7، 8 یان 9 بوو، بەرەو سەرەوە نزیکی بکەرەوە. 5ـێک کە هیچی لە دوا نەبێت حاڵەتێکی تایبەتە: ژمارەکە ڕێک لە نیوەی ڕێگادایە، بۆ نموونە ⁦8.735⁩ لە نێوان ⁦8.73⁩ و ⁦8.74⁩دا. هیچ کام لە دوو دراوسێکە نزیکتر نییە، بۆیە پێویستمان بە یاسایەکە. یاسای قوتابخانە دەڵێت: .

Animation on a number line from 8.730 to 8.740 with the half-way point 8.735 marked. A pointer moves to 8.732 and 8.734 (both round to 8.73), then to 8.735 exactly (rounds up to 8.74 by the school rule), then 8.736 and 8.738 (both 8.74). The last frame colours the left half, 8.730 ≤ x < 8.735, as 8.73 and the right half, 8.735 ≤ x ≤ 8.740, as 8.74.
Animation on a number line from 8.730 to 8.740 with the half-way point 8.735 marked. A pointer moves to 8.732 and 8.734 (both round to 8.73), then to 8.735 exactly (rounds up to 8.74 by the school rule), then 8.736 and 8.738 (both 8.74). The last frame colours the left half, 8.730 ≤ x < 8.735, as 8.73 and the right half, 8.735 ≤ x ≤ 8.740, as 8.74.
Below half-way the number rounds down; from half-way on it rounds up.لە خوار نیوەی ڕێگاوە ژمارەکە بەرەو خوار دەچێت؛ لە نیوەی ڕێگاوە بەرەو سەرەوە.CêIT
Quick checkپشکنینی خێراRound 8.735 to two decimal places with the school rule.⁦8.735⁩ بە یاسای قوتابخانە بۆ دوو نزیک بکەرەوە.

Exactly 5: the half-way caseڕێک 5: نیوەی ڕێگا

“5 or more”, and carrying«5 یان زیاتر» و گواستنەوە

Rounding up can carry into the digits on the left, just as in addition: 19.9999 to two places gives 20.00, and 2.7395 to three places gives 2.740.

بەرەو سەرەوە دەکرێت بگوازرێتەوە بۆ ژمارەکانی لای چەپ، هەروەک لە کۆکردنەوەدا: ⁦19.9999⁩ بۆ دوو خانە دەبێتە ⁦20.00⁩ و ⁦2.7395⁩ بۆ سێ خانە دەبێتە ⁦2.740⁩.

Quick checkپشکنینی خێراRound 2.7395 to three decimal places.⁦2.7395⁩ بۆ سێ نزیک بکەرەوە.

This course's rule: 4 decimal places, rounded at the endیاسای ئەم کۆرسە: 4 خانەی دەیی، لە کۆتاییدا نزیک بکەرەوە

Unless a question asks for something else, this course gives decimal answers to 4 decimal places:

ئەگەر پرسیارێک شتێکی تر نەخوازێت، ئەم کۆرسە وەڵامە دەییەکان بە 4 دەدات:

Exact valueبەهای وردTo 4 placesبە 4 خانە
30/19=1.578947…30/19 = 1.578947\ldots1.5789
2/3=0.666666…2/3 = 0.666666\ldots0.6667
log⁡11=1.041392…\log 11 = 1.041392\ldots1.0414
7=2.645751…\sqrt7 = 2.645751\ldots2.6458
104/7=14.857142…104/7 = 14.857142\ldots14.8571

Round only the final answer. Every rounded number carries a small rounding error, and the errors add up. The 60 values of the next lesson fall into 7 classes with frequencies 4, 5, 9, 12, 16, 7, 7. As percentages of 60 they are exactly 100% together, but rounded to two decimal places they give 6.67+8.33+15.00+20.00+26.67+11.67+11.67=100.016.67 + 8.33 + 15.00 + 20.00 + 26.67 + 11.67 + 11.67 = 100.01, and rounded to whole numbers 7+8+15+20+27+12+12=1017 + 8 + 15 + 20 + 27 + 12 + 12 = 101. Nothing was counted wrong: it is only rounding.

تەنها وەڵامی کۆتایی نزیک بکەرەوە. هەر ژمارەیەکی نزیککراو هەڵدەگرێت، هەرچەندە بچووکیش بێت. ئەم هەڵانە کەڵەکە دەبن. ⁦60⁩ نرخەکەی وانەی داهاتوو دەکەونە 7 بە 4، 5، 9، ⁦12⁩، ⁦16⁩، 7، 7. وەک لە ⁦60⁩، پێکەوە ڕێک ⁦100%⁩ن، بەڵام کە بۆ دوو نزیک بکرێنەوە دەبنە 6.67+8.33+15.00+20.00+26.67+11.67+11.67=100.016.67 + 8.33 + 15.00 + 20.00 + 26.67 + 11.67 + 11.67 = 100.01 و کە بۆ نزیک بکرێنەوە دەبنە 7+8+15+20+27+12+12=1017 + 8 + 15 + 20 + 27 + 12 + 12 = 101. هیچ شتێک بە هەڵە نەژمێردراوە: تەنها .

Definitionپێناسە

The small difference between an exact value and its rounded or stored value. Computers store most decimals in binary, so tiny errors appear.

جیاوازییە بچووکەکەی نێوان نرخێکی ورد و نرخە نزیککراوەکەی یان هەڵگیراوەکەیەتی. کۆمپیوتەر زۆربەی ژمارە دەییەکان بە هەڵدەگرێت، بۆیە هەڵەی زۆر بچووک دەردەکەون.

Quick checkپشکنینی خێراRounded relative frequencies add up to 100.01%. What does that tell you?کۆی دوای دەکاتە ⁦100.01%⁩. ئەمە چی پێ دەڵێیت؟

This course's rule: 4 decimal places, rounded at the endیاسای ئەم کۆرسە: 4 خانەی دەیی، لە کۆتاییدا نزیک بکەرەوە

Round once, at the endیەک جار و لە کۆتاییدا نزیک بکەرەوە

Quick checkپشکنینی خێراIn a long calculation, when should you round?لە ژماردنێکی درێژدا کەی نزیک دەکەیتەوە؟

Rounding, truncating, floor and ceilingنزیککردنەوە، بڕینەوە، نەخشەی گەورەترین ژمارەی تەواو و نەخشەی بچووکترین ژمارەی تەواو

Rounding chooses the closest number. Three other tools always go one way, whatever the dropped digits are:

نزیکترین ژمارە هەڵدەبژێرێت. سێ ئامرازی تر هەمیشە بەرەو یەک لا دەڕۆن، ژمارە فڕێدراوەکان هەرچی بن:

Definitionپێناسە

Shortening a number by simply dropping the digits after a chosen place, without : 8.736 truncated to two is 8.73. In Python, math.trunc() and int() cut off the fraction part.

کورتکردنەوەی ژمارەیەکە تەنها بە فڕێدانی ژمارەکانی دوای شوێنێکی دیاریکراو، بەبێ : ⁦8.736⁩ بە بڕینەوە بۆ دوو دەبێتە ⁦8.73⁩. لە Pythonـدا math.trunc() و int() بەشی کەرتی فڕێ دەدەن.

Four ways to shorten a numberچوار ڕێگا بۆ کورتکردنەوەی ژمارەیەک
ToolئامرازMeaningواتا8.7368.736 to 2 places8.7368.736 بۆ 2 خانە−8.736-8.736 to 2 places−8.736-8.736 بۆ 2 خانە
Roundingclosestنزیکترین8.748.74−8.74-8.74
Truncationcut the extra digits offژمارە زیادەکان ببڕەوە8.738.73−8.73-8.73
Floor ⌊x⌋\lfloor x \rfloor ⌊x⌋\lfloor x \rflooralways down (to the left on the number line)هەمیشە بەرەو خوار (بەرەو چەپ لەسەر )8.738.73−8.74-8.74
Ceiling ⌈x⌉\lceil x \rceil ⌈x⌉\lceil x \rceilalways up (to the right)هەمیشە بەرەو سەرەوە (بەرەو ڕاست)8.748.74−8.73-8.73

Floor ⌊x⌋\lfloor x \rfloor and ceiling ⌈x⌉\lceil x \rceil are explained, with their step graphs, in Piecewise functions: absolute value, floor and ceiling. They give a neat formula for school rounding of a positive number to a whole number: ⌊x+0.5⌋\lfloor x + 0.5 \rfloor. For 8.736: ⌊9.236⌋=9\lfloor 9.236 \rfloor = 9.

⌊x⌋\lfloor x \rfloor و ⌈x⌉\lceil x \rceil لەگەڵ هێڵکارییە پلەدارەکانیان لە نەخشە ڕێسا پەلدارەکان: نرخی ڕووت، نەخشەی گەورەترین ژمارەی تەواو و نەخشەی بچووکترین ژمارەی تەواو ڕوون کراونەتەوە. بۆ قوتابخانە بۆ ، بۆ هاوکێشەیەکی جوان دەدەن: ⌊x+0.5⌋\lfloor x + 0.5 \rfloor. بۆ ⁦8.736⁩: ⌊9.236⌋=9\lfloor 9.236 \rfloor = 9.

When you must round up: when a smaller answer would not be enough. 45 students travel in buses of 20 seats: 45/20=2.2545/20 = 2.25, and 2 buses leave 5 students behind, so you need ⌈2.25⌉=3\lceil 2.25 \rceil = 3. The same happens in the next lesson: a class width of 104/7=14.857104/7 = 14.857 must be rounded up to 15, because a width of 14 would leave the largest values outside the table (see class width).

کەی دەبێت بەرەو سەرەوە نزیک بکەیتەوە: کاتێک وەڵامێکی بچووکتر بەس نییە. ⁦45⁩ قوتابی بە پاسی ⁦20⁩ کورسی گەشت دەکەن: 45/20=2.2545/20 = 2.25، 2 پاس 5 قوتابی بەجێ دەهێڵێت، بۆیە پێویستت بە ⌈2.25⌉=3\lceil 2.25 \rceil = 3 پاسە. لە وانەی داهاتوودا هەمان شت ڕوو دەدات: 104/7=14.857104/7 = 14.857 دەبێت بەرەو سەرەوە بۆ ⁦15⁩ نزیک بکرێتەوە، چونکە پانیی ⁦14⁩ گەورەترین نرخەکان لە دەرەوەی خشتەکە دەهێڵێتەوە (سەیری پانیی کلاس بکە).

PYTHONType in a terminalلە تێرمیناڵدا بینووسە
import math

x = 8.736
print(round(x, 2))                  # nearest: 8.74
print(math.trunc(x * 100) / 100)    # cut off the rest
print(math.floor(x * 100) / 100)    # always down
print(math.ceil(x * 100) / 100)     # always up
print(math.ceil(104 / 7))           # a class width must be rounded up
Quick checkپشکنینی خێرا62 people need taxis that carry 4 passengers each. How many taxis?⁦62⁩ کەس پێویستیان بە تاکسییە کە هەریەکەیان 4 سەرنشین هەڵدەگرێت. چەند تاکسی؟

Rounding in Python: round half to evenنزیککردنەوە لە Pythonـدا: نیوە بۆ جووت

Python's round() does not use the school rule for exact halves. It uses round half to even: an exact half goes to the neighbour whose last digit is even. The basics of round() are in Operators and expressions; here is what it means for statistics.

round()ـی Python بۆ نیوە ڕێکەکان یاسای قوتابخانە بەکار ناهێنێت. بەکار دەهێنێت: نیوەیەکی ڕێک دەچێت بۆ ئەو دراوسێیەی کە دوایین ژمارەی جووتە. بنەماکانی round() لە کارپێکەرەکان و دەربڕینەکاندان؛ لێرەدا دەبینین چ واتایەکی بۆ هەیە.

Definitionپێناسە

A rounding rule that sends an exact half to the nearest even digit, so ties do not always go up. Python's round() uses it.

یاسایەکی کە نیوەی ڕێک دەنێرێت بۆ نزیکترین ژمارەی جووت، بۆیە هاوتاکان هەمیشە بەرەو سەرەوە ناچن. round()ـی Python ئەمە بەکار دەهێنێت.

PYTHONType in a terminalلە تێرمیناڵدا بینووسە
print(round(8.736, 2))                              # the cut-line example
print(round(0.5), round(1.5), round(2.5), round(3.5))   # exact halves go to the even neighbour
print(round(0.125, 2))                              # 0.125 is stored exactly: a true tie
print(round(2.675, 2))                              # a surprise: see below

Why even? Imagine rounding many exact halves. The school rule always goes up, so the total drifts upwards. Half to even sends half of them up and half down, so the total stays fair:

بۆچی جووت؟ وێنا بکە زۆر نیوەی ڕێک نزیک دەکەیتەوە. یاسای قوتابخانە هەمیشە بەرەو سەرەوە دەچێت، بۆیە کۆی گشتی بەرەو سەرەوە دەخزێت. نیوە بۆ جووت نیوەیان بەرەو سەرەوە و نیوەیان بەرەو خوار دەنێرێت، بۆیە کۆی گشتی دادپەروەر دەمێنێتەوە:

PYTHONType in a terminalلە تێرمیناڵدا بینووسە
ties = [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5]

print(sum(ties))                          # the true total
print(sum(round(t) for t in ties))        # Python: half to even
print(sum(int(t + 0.5) for t in ties))    # school rule: half up

This is why half to even is the default rule for floating-point numbers in computers (the IEEE 754 standard) and in Python's decimal module; in money matters it is also called banker's rounding. By hand, in this course, use the school rule.

لەبەر ئەمەیە کە نیوە بۆ جووت یاسای بنەڕەتیی لە کۆمپیوتەردایە (ستانداردی ⁦IEEE 754⁩) و decimalـی Pythonـیش هەر ئەمە بەکار دەهێنێت؛ لە کاروباری پارەدا پێی دەڵێن بانکی. بە دەست، لەم کۆرسەدا، یاسای قوتابخانە بەکار بهێنە.

Quick checkپشکنینی خێراWhat does round(4.5) print in Python?round(4.5) لە Pythonـدا چی چاپ دەکات؟

Rounding in Python: round half to evenنزیککردنەوە لە Pythonـدا: نیوە بۆ جووت

Why round(2.675, 2) gives 2.67بۆچی round(2.675, 2) دەکاتە ⁦2.67⁩

This is not the half-to-even rule (with an exact half the even neighbour would be 2.68). The reason is storage. A float (decimal numbers in Python) keeps numbers in binary, and 2.675 has no exact binary form. Python stores the closest binary number, which is a tiny bit smaller than 2.675 — so it is below half-way and rounds down:

ئەمە یاسای نیوە بۆ جووت نییە (بە نیوەیەکی ڕێک دراوسێ جووتەکە ⁦2.68⁩ دەبوو). هۆکارەکە هەڵگرتنە. Python هەر (ژمارە کەرتییەکان لە Pythonـدا) بە هەڵدەگرێت و ⁦2.675⁩ هیچ شێوەیەکی وردی نییە. Python نزیکترین ژمارەی هەڵدەگرێت کە کەمێک بچووکترە لە ⁦2.675⁩ — بۆیە لە خوار نیوەی ڕێگاوەیە و بەرەو خوار دەچێت:

PYTHONType in a terminalلە تێرمیناڵدا بینووسە
from decimal import Decimal

print(Decimal(2.675))     # the number the float really holds
print(Decimal("2.675"))   # the decimal number you typed

To round exactly by the school rule, give the number to the decimal module as text and ask for ROUND_HALF_UP:

بۆ ئەوەی بە وردی بە یاسای قوتابخانە نزیک بکەیتەوە، ژمارەکە وەک دەق بدە بە decimal و داوای ROUND_HALF_UP بکە:

PYTHONType in a terminalلە تێرمیناڵدا بینووسە
from decimal import Decimal, ROUND_HALF_UP

def round_half_up(text, places):
    step = Decimal(1).scaleb(-places)       # 0.01 when places = 2
    return Decimal(text).quantize(step, rounding=ROUND_HALF_UP)

print(round_half_up("2.675", 2))
print(round_half_up("2.7395", 3))
print(round_half_up("8.736", 2))
print(round_half_up("12.995", 2))
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

scaleb(-places) turns 1 into 0.01 (for 2 places), the step to round to.

scaleb(-places) 1 دەکاتە ⁦0.01⁩ (بۆ 2 خانە)، ئەو هەنگاوەی بۆی نزیک دەکەینەوە.

Lineدێڕی 5

Decimal(text) keeps exactly the digits you typed; ROUND_HALF_UP sends halves away from zero, like the school rule.

Decimal(text) ڕێک ئەو ژمارانە دەهێڵێتەوە کە نووسیوتن؛ ROUND_HALF_UP نیوەکان دوور لە سفر دەنێرێت، وەک یاسای قوتابخانە.

Quick checkپشکنینی خێراWhy does round(2.675, 2) give 2.67 in Python?بۆچی round(2.675, 2) لە Pythonـدا ⁦2.67⁩ دەدات؟

Why Is This Happening?! Floating Point Approximationb001 · Englishئینگلیزی · 162K viewsبینین · 5.3K likesلایک

Why 0.7 + 0.6 does not print exactly 1.3: computers store decimals in binary, so floats are approximations.

بۆچی Python بۆ 0.7 + 0.6 ژمارەی 1.2999999999999998 پیشان دەدات: ژمارەی بە هەڵدەگرێت، بۆیە زۆر ژمارەی سادە تەنها نزیکەیین.

Explains the binary storage behind surprises like round(2.675, 2).

هۆکاری ئەنجامی چاوەڕواننەکراوی وەک round(2.675, 2) ڕوون دەکاتەوە: هەڵگرتنی ژمارەکان بە .

Common mistakesهەڵە باوەکان

MistakeهەڵەExampleنموونەCorrectدروست
Cutting off instead of rounding لە جیاتی 8.736→8.738.736 \to 8.738.748.74
“More than 5” ruleیاسای «زیاتر لە 5»2.7395→2.7392.7395 \to 2.7392.7402.740
Rounding twiceدوو جار 2.346→2.35→2.42.346 \to 2.35 \to 2.42.32.3
Forgetting the carryلەبیرکردنی گواستنەوە19.9999→19.10019.9999 \to 19.10020.0020.00
Dropping a needed final 0لابردنی 0ـی کۆتایی کە پێویستە2.740 written as 2.74 when 3 places are asked⁦2.740⁩ وەک ⁦2.74⁩ نووسراوە کاتێک 3 خانە داوا کراوە2.7402.740
Rounding a class width to the nearest بۆ نزیکترین نزیک کراوەتەوە50/8=6.25→650/8 = 6.25 \to 6, but 8×6=48<508 \times 6 = 48 < 50: the largest values are left out50/8=6.25→650/8 = 6.25 \to 6، بەڵام 8×6=48<508 \times 6 = 48 < 50: گەورەترین نرخەکان دەمێننە دەرەوەround up: 7بەرەو سەرەوە: 7
Expecting round() to follow the school ruleچاوەڕوانی ئەوە کە round() یاسای قوتابخانە بەکار بهێنێتround(2.5) → 2use decimal with ROUND_HALF_UPdecimal لەگەڵ ROUND_HALF_UP بەکار بهێنە
Quick checkپشکنینی خێراA student rounds 4.4449 to one decimal place in steps: 4.445→4.45→4.54.445 \to 4.45 \to 4.5. What is the correct answer?قوتابییەک ⁦4.4449⁩ بە چەند هەنگاوێک بۆ یەک نزیک دەکاتەوە: 4.445→4.45→4.54.445 \to 4.45 \to 4.5. وەڵامی دروست چییە؟

Exercisesڕاهێنانەکان

ExerciseڕاهێنانRound by handبە دەست نزیک بکەرەوە

Round each number with the school rule: (a) 3.14159 to 2 and to 4 places; (b) 0.0049 to 2 places; (c) 12.995 to 2 places; (d) 7.45 to 1 place; (e) 19.9999 to 2 places; (f) 2.0451 to 2 places. You can check your answers with an online rounding calculator such as the one the course notes link to (calculatorsoup.com); it uses the same half-up rule.

هەر ژمارەیەک بە یاسای قوتابخانە نزیک بکەرەوە: (أ) ⁦3.14159⁩ بۆ 2 و بۆ 4 خانە؛ (ب) ⁦0.0049⁩ بۆ 2 خانە؛ (ج) ⁦12.995⁩ بۆ 2 خانە؛ (د) ⁦7.45⁩ بۆ 1 خانە؛ (هـ) ⁦19.9999⁩ بۆ 2 خانە؛ (و) ⁦2.0451⁩ بۆ 2 خانە. دەتوانیت وەڵامەکانت بە ئۆنلاینی بپشکنیت، وەک ئەوەی تێبینییەکانی کۆرسەکە بەستەری بۆ داناوە (⁦calculatorsoup.com⁩)؛ هەمان یاسای نیوە بۆ سەرەوە بەکار دەهێنێت.

Show answerوەڵامەکە پیشان بدە
  • (a) 3.14 and 3.1416
  • (b) 0.00 — the dropped digit is 4
  • (c) 13.00 — the 5 rounds up and carries twice
  • (d) 7.5 — the dropped digit is 5
  • (e) 20.00 — the carry runs to the left
  • (f) 2.05 — only the first dropped digit (5) counts
  • (أ) ⁦3.14⁩ و ⁦3.1416⁩
  • (ب) ⁦0.00⁩ — ژمارەی فڕێدراو 4ـە
  • (ج) ⁦13.00 — 5⁩ـەکە بەرەو سەرەوە دەچێت و دوو جار دەگوازرێتەوە
  • (د) ⁦7.5⁩ — ژمارەی فڕێدراو 5ـە
  • (هـ) ⁦20.00⁩ — گواستنەوەکە بەرەو چەپ دەڕوات
  • (و) ⁦2.05⁩ — تەنها یەکەم ژمارەی فڕێدراو ⁦(5)⁩ گرنگە
ExerciseڕاهێنانSpot the mistakeهەڵەکە بدۆزەرەوە

“2.7395 to three decimal places is 2.739, because the next digit, 5, is not more than 5.” What is wrong?

«⁦2.7395⁩ بۆ سێ دەکاتە ⁦2.739⁩، چونکە ژمارەی دواتر، 5، زیاتر نییە لە 5.» چی هەڵەیە؟

Show answerوەڵامەکە پیشان بدە

The rule is “5 or more rounds up”, not “more than 5”. The answer is 2.740.

یاساکە «5 یان زیاتر بەرەو سەرەوە»یە نەک «زیاتر لە 5». وەڵامەکە ⁦2.740⁩ـە.

Exercisesڕاهێنانەکان

More exercisesڕاهێنانی زیاتر

ExerciseڕاهێنانPredict Pythonپێشبینیی Python بکە

Without running it, predict what this prints. Then run it and explain each line.

بەبێ کارپێکردن پێشبینی بکە ئەمە چی چاپ دەکات. پاشان کاری پێ بکە و هەر دێڕێک ڕوون بکەرەوە.

PYTHONType in a terminalلە تێرمیناڵدا بینووسە
print(round(6.5), round(7.5))
print(round(12.995, 2))
Show answerوەڵامەکە پیشان بدە
PYTHONType in a terminalلە تێرمیناڵدا بینووسە
print(round(6.5), round(7.5))
print(round(12.995, 2))

6.5 and 7.5 are exact halves: they go to the even neighbours 6 and 8. 12.995 is stored slightly below 12.995, so it rounds down to 12.99; by hand (school rule) it is 13.00.

⁦6.5⁩ و ⁦7.5⁩ نیوەی ڕێکن: دەچن بۆ دراوسێ جووتەکانیان 6 و ⁦8. 12.995⁩ کەمێک لە خوار ⁦12.995⁩ـەوە هەڵدەگیرێت، بۆیە دەبێتە ⁦12.99⁩؛ بە دەست (یاسای قوتابخانە) دەکاتە ⁦13.00⁩.

ExerciseڕاهێنانRound up or to the nearest?بەرەو سەرەوە یان بۆ نزیکترین؟

For each case, say whether you round to the nearest whole number or always up: (a) the average mark of a class, 67.4; (b) the number of 30-seat classrooms for 95 students; (c) a class width of 50/850/8.

بۆ هەر حاڵەتێک بڵێ بۆ نزیکترین نزیک دەکەیتەوە یان هەمیشە بەرەو سەرەوە: (أ) نمرەی پۆلێک، ⁦67.4⁩؛ (ب) ژمارەی پۆلی ⁦30⁩ کورسی بۆ ⁦95⁩ قوتابی؛ (ج) 50/850/8.

Show answerوەڵامەکە پیشان بدە
  • (a) nearest: 67 (or keep 67.4)
  • (b) up: 95/30≈3.17→495/30 \approx 3.17 \to 4 classrooms
  • (c) up: 50/8=6.25→750/8 = 6.25 \to 7, so that the classes cover the whole range
  • (أ) نزیکترین: ⁦67⁩ (یان ⁦67.4⁩ بهێڵەرەوە)
  • (ب) سەرەوە: 95/30≈3.17→495/30 \approx 3.17 \to 4 پۆل
  • (ج) سەرەوە: 50/8=6.25→750/8 = 6.25 \to 7، بۆ ئەوەی هەموو بگرنەوە

Summaryپوختە

  • Rounding replaces a number with the closest number that has the wanted number of decimal places.
  • Cut after the last kept place and look at the first dropped digit: 0–4 keep, 5–9 round up.
  • This course: 4 decimal places, rounded only at the end, rounded once.
  • Truncation, floor and ceiling always go one way; class widths are always rounded up.
  • Python's round() sends exact halves to the even neighbour, and binary floats can make a ‘half’ slightly smaller or larger.
  • ژمارەیەک بە نزیکترین ژمارە دەگۆڕێت کە ژمارەی داواکراوی هەبێت.
  • لە دوای دوایین خانەی هێڵراوە ببڕە و سەیری یەکەم ژمارەی فڕێدراو بکە: ⁦0–4⁩ وەک خۆی، ⁦5–9⁩ بەرەو سەرەوە.
  • ئەم کۆرسە: 4 ، تەنها لە کۆتاییدا و یەک جار نزیک دەکرێتەوە.
  • ، و هەمیشە بەرەو یەک لا دەڕۆن؛ هەمیشە بەرەو سەرەوە نزیک دەکرێتەوە.
  • round()ـی Python نیوە ڕێکەکان دەنێرێت بۆ دراوسێ جووتەکە و دەتوانن «نیوەیەک» کەمێک بچووکتر یان گەورەتر بکەن.
Review questionsپرسیارەکانی پێداچوونەوە
Round 8.736 to two decimal places and explain.⁦8.736⁩ بۆ دوو خانەی دەیی نزیک بکەرەوە و ڕوونی بکەرەوە.

8.74: the first dropped digit is 6, which is 5 or more, so 73 becomes 74.

⁦8.74⁩: یەکەم ژمارەی فڕێدراو 6ـە کە 5 یان زیاترە، بۆیە ⁦73⁩ دەبێتە ⁦74⁩.

Why can rounded percentages add up to 100.01?بۆچی کۆی ڕێژە سەدییەکان دوای نزیککردنەوە دەکرێت ببێتە ⁦100.01⁩؟

Each one carries a small rounding error, and the errors add up.

هەریەکەیان هەڵدەگرێت و هەڵەکان کۆ دەبنەوە.

What is round(2.5) in Python, and why?round(2.5) لە Pythonـدا چەندە و بۆچی؟

2, because Python rounds exact halves to the even neighbour.

2، چونکە Python نیوە ڕێکەکان بۆ دراوسێ جووتەکە نزیک دەکاتەوە.

Lesson complete!وانەکە تەواو بوو!

Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.

Key termsزاراوە سەرەکییەکان

Next lessonوانەی داهاتوو

Grouping Data: Frequency Tablesپۆلێنکردنی دراوە: خشتەکانی دووبارەبوونەوە

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.