ArticleslgStudy

computer science

Rounding

Rounding is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Rounding rather than just read about it. In short: Rounding or rounding off is the process of adjusting a number to an approximate, more convenient value, often with a shorter or simpler representation. For example, replacing $23.4476 with $23.45, the fraction 312/937 with 1/3, or the expression √2 with 1.414.

Rounding — main illustration
Rounding — illustration

Key takeaways

  • Rounding belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Rounding to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Rounding from memory before moving on to harder problems.

Reference excerpt

Rounding or rounding off is the process of adjusting a number to an approximate, more convenient value, often with a shorter or simpler representation. For example, replacing $23.4476 with $23.45, the fraction 312/937 with 1/3, or the expression √2 with 1.414. Rounding is often done to obtain a value that is easier to report and communicate than the original. Rounding can also be important to avoid misleadingly precise reporting of a computed number, measurement, or estimate; for example, a quantity that was computed as 123456 but is known to be accurate only to within a few hundred units is usually better stated as "about 123500". On the other hand, rounding of exact numbers will introduce some round-off error in the reported result. Rounding is almost unavoidable when reporting many computations – especially when dividing two numbers in integer or fixed-point arithmetic; when computing mathematical functions such as square roots, logarithms, and sines; or when using a floating-point representation with a fixed number of significant digits. In a sequence of calculations, these rounding errors generally accumulate, and in certain ill-conditioned cases they may make the result meaningless. Accurate rounding of transcendental mathematical functions is difficult because the number of extra digits that need to be calculated to resolve whether to round up or down cannot be known in advance. This problem is known as "the table-maker's dilemma". Rounding has many similarities to the quantization that occurs when physical quantities must be encoded by numbers or digital signals. A wavy equals sign (≈) is sometimes used to indicate rounding of exact numbers, e.g. 9.98 ≈ 10. This sign was introduced by Alfred George Greenhill in 1892. Ideal characteristics of rounding methods include:

Rounding should be done by a function. This way, when the same input is rounded in different instances, the output is unchanged. Calculations done with rounding should be close to those done without rounding. As a result of (1) and (2), the output from rounding should be close to its input, often as close as possible. To be considered rounding, the range will be a subset of the domain, often discrete. A classical range is the integers. Rounding should preserve symmetries that already exist between the domain and range. With finite precision (or a discrete domain), this translates to removing bias. A rounding method should have utility in computer science or human arithmetic where finite precision is used, and speed is a consideration. Because it is not usually possible for a method to satisfy all ideal characteristics, many different rounding methods exist. As a general rule, rounding is idempotent; i.e., once a number has been rounded, rounding it again to the same precision will not change its value. Rounding functions are also monotonic; i.e., rounding two numbers to the same absolute precision will not exchange their order (but may give the same value). In the general case of a discrete range, they are piecewise constant functions.

Types of rounding Typical rounding problems include:

Rounding to integer The most basic form of rounding is to replace an arbitrary number by an integer. All the following rounding modes are concrete implementations of an abstract single-argument "round()" procedure. These are true functions (with the exception of those that use randomness).

Directed rounding to an integer These four methods are called directed rounding to an integer, as the displacements from the original number x to the rounded value y are all directed toward or away from the same limiting value (0, +∞, or −∞). Directed rounding is used in interval arithmetic and is often required in financial calculations. If x is positive, round-down is the same as round-toward-zero, and round-up is the same as round-away-from-zero. If x is negative, round-down is the same as round-away-from-zero, and round-up is the same as round-toward-zero. In any case, if x is an integer, y is just x. Where many calculations are done in sequence, the choice of rounding method can have a very significant effect on the result. A famous instance involved a new index set up by the Vancouver Stock Exchange in 1982. It was initially set at 1000.000 (three decimal places of accuracy), and after 22 months had fallen to about 520, although the market appeared to be rising. The problem was caused by the index being recalculated thousands of times daily, and always being truncated (rounded down) to 3 decimal places, in such a way that the rounding errors accumulated. Recalculating the index for the same period using rounding to the nearest thousandth rather than truncation corrected the index value from 524.811 up to 1098.892. For the examples below, sgn(x) refers to the sign function applied to the original number, x.

Rounding down One may round down (or take the floor, or round toward negative infinity): y is the largest integer that does not exceed x.

y = f l o o r ( x ) = ⌊ x ⌋ = − ⌈ − x ⌉ {\displaystyle y=\mathrm {floor} (x)=\left\lfloor x\right\rfloor =-\left\lceil -x\right\rceil }

For example, 23.7 gets rounded to 23, and −23.2 gets rounded to −24.

Rounding up One may also round up (or take the ceiling, or round toward positive infinity): y is the smallest integer that is not less than x.

y = ceil ⁡ ( x ) = ⌈ x ⌉ = − ⌊ − x ⌋ {\displaystyle y=\operatorname {ceil} (x)=\left\lceil x\right\rceil =-\left\lfloor -x\right\rfloor }

For example, 23.2 gets rounded to 24, and −23.7 gets rounded to −23.

Rounding toward zero One may also round toward zero (or truncate, or round away from infinity): y is the integer that is closest to x such that it is between 0 and x (included); i.e. y is the integer part of x, without its fraction digits.

… excerpt ends here. Continue reading the full article.

Illustrations

Rounding: Graphs of the result, y, of rounding x using different methods. For clarity, the graphs are shown displaced from integer y values. In the SVG file, hover over a method to highlight it and, in SMIL-enabled browsers, click to select or deselect it.
Graphs of the result, y, of rounding x using different methods. For clarity, the graphs are shown displaced from integer y values. In the SVG file, hover over a method to highlight it and, in SMIL-enabled browsers, click to select or deselect it.

Worked examples

Example 1 — a first encounter with Rounding

Start with the simplest possible case. Write down what Rounding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Rounding before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Rounding ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Rounding

In research
Rounding appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Rounding in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Rounding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Arithmetic, Computer arithmetic, Statistical data transformation, so understanding it makes those chapters shorter.
In everyday life
Look for Rounding outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Rounding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Rounding means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Rounding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Rounding in simple terms?

Rounding or rounding off is the process of adjusting a number to an approximate, more convenient value, often with a shorter or simpler representation. For example, replacing $23.4476 with $23.45, the fraction 312/937 with 1/3, or the expression √2 with 1.414.

Why does Rounding matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Rounding?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Rounding.

Tags

  • Arithmetic
  • Computer arithmetic
  • Statistical data transformation
  • Theory of computation

Keep exploring