Número truncado
O truncamento reduz a precisão para zero e não aplica regras de arredondamento ou empate.
What Is Truncation?
Truncation removes digits from a number beyond a specified position without rounding the remaining digits. For decimal numbers, truncation toward zero removes the unwanted fractional digits while keeping the number closer to zero.
How Does Truncation Work?
Applying truncation requires following a simple, strict rule:
Start with the original number
For example, take the number 45.6789.
Choose the position to keep
Decide the number of decimal places to retain (e.g., 2 decimal places).
Keep digits through that position
Identify the digits up to the cut-off point (45.67).
Remove all digits after
Discard everything else (89). Do not change the retained digits, yielding 45.67. No rounding occurs.
How to Truncate a Number to a Whole Number
Truncation to a whole number simply removes the entire fractional portion of the value, leaving only the integer.
- 2.99 → 2
- 2.01 → 2
- −2.99 → −2
- −2.01 → −2
Notice that for negative numbers, truncation removes the fraction, meaning the result moves closer to zero. This is critically different from the mathematical floor function.
Truncation of −2.99 = −2
How to Truncate to Decimal Places
To truncate a number to a specific number of decimal places, you simply keep that many digits after the decimal point and delete the rest.
Example for 12.9876:
- 1 decimal place: 12.9876 → 12.9
- 2 decimal places: 12.9876 → 12.98
- 3 decimal places: 12.9876 → 12.987
- 4 decimal places: 12.9876 → 12.9876
Example for −12.9876 (The sign does not change):
- 1 decimal place: −12.9876 → −12.9
- 2 decimal places: −12.9876 → −12.98
- 3 decimal places: −12.9876 → −12.987
How Does Truncation Handle Negative Numbers?
Truncation toward zero moves negative numbers strictly toward zero.
Because the negative sign remains unchanged and the fractional part is simply deleted, the resulting value is technically greater than the original (e.g. −3 is greater than −3.9).
- −3.9 → −3
- −3.5 → −3
- −3.1 → −3
- −3.99 to 1 decimal place → −3.9
- −3.99 to 2 decimal places → −3.99
| Method | Input: −3.9 | Result |
|---|---|---|
| Truncate | −3.9 | −3 |
| Floor | −3.9 | −4 |
| Ceiling | −3.9 | −3 |
This is a critical distinction: truncation behaves identically to the ceiling function for negative values, whereas it behaves like the floor function for positive values.
How Does Truncation Handle Positive Numbers?
For positive numbers, the fractional digits are simply removed, meaning the number moves toward zero (downward on the number line).
- 3.9 → 3
- 3.99 → 3
- 15.678 → 15.67
- 123.4567 → 123.45
What Happens When the Number Is Already an Integer?
If the number is already an integer (a whole number), truncation leaves it completely unchanged because there are no fractional digits to remove.
- 5 → 5
- 0 → 0
- −5 → −5
- 100 → 100
What Is the Truncation of Zero?
Truncating zero or any variation of zero simply results in zero.
- 0 → 0
- 0.0 → 0
- −0.5 → 0 (when truncating toward zero to a whole number)
Truncating Fractions
Truncation can also apply after evaluating a fraction into its decimal form.
Example 1: 7 / 3 = 2.333...
Truncate to 2 decimal places: 2.33
Example 2: 11 / 4 = 2.75
Truncate to 1 decimal place: 2.7
Example 3: −7 / 3 = −2.333...
Truncate toward zero to 2 decimal places: −2.33
Truncation Examples
| Input | Target | Truncated Result | Explanation |
|---|---|---|---|
| 2.99 | Whole number | 2 | Remove the fractional part |
| −2.99 | Whole number | −2 | Move toward zero |
| 45.6789 | 2 decimal places | 45.67 | Remove digits after the second decimal |
| 12.9876 | 1 decimal place | 12.9 | Remove digits after the first decimal |
| −12.9876 | 2 decimal places | −12.98 | Remove digits after the second decimal |
| 7.999 | 2 decimal places | 7.99 | No rounding occurs |
Truncation Formula
The mathematical concept behind truncating toward zero to a specific number of decimal places (n) involves scaling the number, dropping the fraction, and scaling back.
This works by:
- Multiplying by 10ⁿ to move the target decimal place to the integer position.
- Truncating toward zero to drop the remaining fractional portion.
- Dividing by 10ⁿ to restore the original decimal placement.
Positive Example
Truncate 12.987 to 2 decimal places:
- 12.987 × 100 = 1298.7
- trunc(1298.7) = 1298
- 1298 / 100 = 12.98
Negative Example
Truncate −12.987 to 2 decimal places:
- −12.987 × 100 = −1298.7
- trunc(−1298.7) = −1298
- −1298 / 100 = −12.98
Truncation Function
Mathematically, truncation toward zero for a real number x can be defined piecewise using the floor and ceiling functions:
trunc(x) = ceiling(x) when x < 0
Alternatively, using the sign function (sgn or sign) and absolute value (|x|):
Both formulas mathematically enforce the "move toward zero" rule for both positive and negative values.
Truncation vs Rounding
Truncation and rounding are fundamentally different operations. Truncation simply ignores the discarded digits entirely. Rounding uses the discarded digits to decide whether the retained digits should be increased.
Example 1: 2.987
- Truncate to 2 decimal places: 2.98
- Round to 2 decimal places: 2.99
Example 2: 2.983
- Truncate to 2 decimal places: 2.98
- Round to 2 decimal places: 2.98
Example 3: −2.987
- Truncate toward zero: −2.98
- Round to nearest hundredth: −2.99
Truncation does not imply that it is a type of nearest-value rounding; it is a separate cutoff mechanism.
Truncation vs Floor Function
Truncation moves values toward zero. The floor function moves values toward negative infinity.
For positive numbers, they act identically. For negative numbers, they move in opposite directions. This makes the negative-number difference extremely clear.
| Input | Truncate (Toward Zero) | Floor (Toward −∞) |
|---|---|---|
| 2.7 | 2 | 2 |
| 2.1 | 2 | 2 |
| −2.1 | −2 | −3 |
| −2.7 | −2 | −3 |
| −5.9 | −5 | −6 |
Truncation vs Ceiling Function
Truncation moves toward zero. The ceiling function moves toward positive infinity.
For negative values, truncation and ceiling often produce the same integer result because moving toward positive infinity from a negative decimal leads to zero. For positive numbers, they differ.
| Input | Truncate | Ceiling |
|---|---|---|
| 2.7 | 2 | 3 |
| −2.7 | −2 | −2 |
| −2.1 | −2 | −2 |
Is Truncation the Same as Rounding Down?
No. Truncation toward zero and mathematical floor rounding (often informally called "rounding down") are different operations for negative numbers.
Consider the value −2.7:
- Truncation → −2
- Floor (Rounding Down) → −3
Because the term "round down" can be ambiguous, always clarify whether you mean moving strictly toward negative infinity (floor) or stripping digits toward zero (truncate).
Truncation vs Round Half Up
Round Half Up considers the next digit to decide whether to change the retained value, pushing exact ties away from zero.
For 2.65 to 1 decimal place:
- Truncation → 2.6
- Round Half Up → 2.7
For −2.65 to 1 decimal place:
- Truncation → −2.6
- Round Half Up → −2.7
Truncation vs Banker's Rounding
Banker's Rounding is a nearest-value rule with special handling for exact halfway cases. Truncation simply removes digits without any tie-breaking rules.
For 2.65 to 1 decimal place (exact halfway, retaining an even digit):
- Truncation → 2.6
- Banker's rounding → 2.6
For 2.75 to 1 decimal place (exact halfway, retaining an odd digit):
- Truncation → 2.7
- Banker's rounding → 2.8
Truncation on a Number Line
Visually, truncation always pulls a non-integer value inward toward zero on the number line.
- For positive values (2.8 → 2), it pulls the value to the left (toward zero).
- For negative values (−2.8 → −2), it pulls the value to the right (toward zero).
Compare this to floor, which always moves to the left (−2.8 → −3) regardless of the sign.
When Should You Use Truncation?
Truncation is highly specific and should be used depending on the requirements of the calculation. You should use truncation when:
- Displaying a fixed number of decimal places without rounding.
- Removing extra precision entirely.
- Processing measurements where the specified cutoff is intentional.
- Performing certain programming and data-processing tasks.
- Implementing controlled numerical display where increasing the displayed value would be undesirable.
Truncation is not always better or worse; it simply serves distinct analytical needs compared to standard rounding.
Real-World Uses of Truncation
Concrete examples where truncation is preferred include:
- Financial display: Some specific financial displays explicitly require truncating partial cents downward to prevent showing inflated balances, though actual arithmetic often requires specific rounding rules.
- Measurement data and sensor values: Dropping excessive precision from sensor noise before storage to save space.
- Digital displays: Progress bars showing 99.9% complete will often truncate to 99% to prevent prematurely displaying 100%.
- Data reporting: Statistics and data preprocessing often employ truncation to bucket demographic data securely.
- Scientific calculations: Environments where a fixed cutoff is required by a strict protocol.
Truncation in Programming
Programming languages provide different functions specifically intended for truncating values.
Truncation in Python
Use the math.trunc() function from the math module to truncate a number toward zero. Do not confuse it with math.floor().
math.trunc(2.99) // Returns 2
math.trunc(-2.99) // Returns -2
Truncation in JavaScript
Use the Math.trunc() function to easily remove the fractional digits of a number toward zero.
Math.trunc(-2.99) // Returns -2
Truncation in Java
In Java, explicitly casting a floating-point number to an integer performs mathematical truncation.
(int) -2.99 // Returns -2
Truncation in C#
Use Math.Truncate() which removes the fractional part toward zero.
Math.Truncate(-2.99) // Returns -2
Truncation in Excel
Use the TRUNC(number, num_digits) function. By default, it truncates to a whole number, but you can easily specify decimal places.
TRUNC(-2.987, 2) // Returns -2.98
TRUNC(2.987) // Returns 2
Truncation in SQL
Different database systems use different functions. PostgreSQL and Oracle offer a native TRUNC() function, whereas SQL Server often relies on ROUND(value, decimals, 1) to force truncation instead of rounding.
Common Truncation Mistakes
- Thinking truncation means nearest rounding: Correction — Truncation ignores discarded digits entirely and never rounds up.
- Thinking truncation always moves downward: Correction — It moves toward zero. For negative numbers, this means the value technically moves upward (e.g. −3.9 becomes −3).
- Confusing truncation with floor: Correction — Floor moves toward negative infinity. Truncation moves toward zero.
- Confusing truncation with ceiling: Correction — Ceiling moves toward positive infinity. Truncation moves toward zero.
- Forgetting negative numbers move toward zero: Correction — −2.9 truncates to −2, not −3.
- Using truncation when nearest rounding is required: Correction — Do not use truncation to approximate values; use it only when a hard cutoff is desired.
- Assuming discarded digits affect the retained digits: Correction — Truncation never adjusts the retained digit based on what was removed.
- Confusing decimal display formatting with mathematical truncation: Correction — UI components that hide decimals sometimes apply rounding under the hood. Verify your display layer.
- Using truncation in financial calculations without checking the required rules: Correction — Financial math often mandates standardized rounding rules to avoid destroying value.
Truncation Quick Reference
Truncation toward zero removes the fractional part without rounding the remaining value.
| Input | Truncate to Whole Number |
|---|---|
| 2.9 | 2 |
| 2.1 | 2 |
| −2.9 | −2 |
| −2.1 | −2 |
| 5 | 5 |
| −5 | −5 |
Truncation Practice
Test your knowledge with these examples. Click to reveal the truncated answers.