截断数

截断将精度降低到零,并且不应用向上舍入或平局规则。

🔢
舍入计算器
输入数字并选择您的舍入首选项
|
🧪 快速示例

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.

2.987 → 2.98
2.987 → 2.9
−2.987 → −2.98
2.987 → 2

How Does Truncation Work?

Applying truncation requires following a simple, strict rule:

1

Start with the original number

For example, take the number 45.6789.

2

Choose the position to keep

Decide the number of decimal places to retain (e.g., 2 decimal places).

3

Keep digits through that position

Identify the digits up to the cut-off point (45.67).

4

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.

Floor of −2.99 = −3
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.99Whole number2Remove the fractional part
−2.99Whole number−2Move toward zero
45.67892 decimal places45.67Remove digits after the second decimal
12.98761 decimal place12.9Remove digits after the first decimal
−12.98762 decimal places−12.98Remove digits after the second decimal
7.9992 decimal places7.99No 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.

trunc(x × 10ⁿ) / 10ⁿ

This works by:

  1. Multiplying by 10ⁿ to move the target decimal place to the integer position.
  2. Truncating toward zero to drop the remaining fractional portion.
  3. 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) = floor(x) when x ≥ 0
trunc(x) = ceiling(x) when x < 0

Alternatively, using the sign function (sgn or sign) and absolute value (|x|):

trunc(x) = sign(x) × floor(|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.722
2.122
−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.723
−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().

import math
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
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
(int) -2.99 // Returns -2

Truncation in C#

Use Math.Truncate() which removes the fractional part toward zero.

Math.Truncate(2.99) // Returns 2
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, 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.92
2.12
−2.9−2
−2.1−2
55
−5−5

Truncation Practice

Test your knowledge with these examples. Click to reveal the truncated answers.

Truncate 8.765 to 2 decimal places.
8.76
Truncate −8.765 to 2 decimal places.
−8.76
Truncate 9.999 to a whole number.
9
Truncate −9.999 to a whole number.
−9
Truncate 45.6789 to 3 decimal places.
45.678
Truncate 0.005 to 2 decimal places.
0.00
Truncate 100.1 to a whole number.
100
Truncate −3.14159 to 3 decimal places.
−3.141
Truncate 15 / 4 (3.75) to a whole number.
3
Truncate −15 / 4 (−3.75) to a whole number.
−3

常见问题解答

什么是截断?
截断是从数字中删除超出指定位置的数字而不对剩余数字进行四舍五入的过程。
数学中的截断是什么意思?
在数学中,截断数字意味着截断其小数部分,使值更接近于零,而不应用最近值平局规则。
什么是截断数计算器?
截断数字计算器是一种工具,可以自动将数字中不需要的数字删除到指定的精度,从而确保不会发生舍入。
如何截断一个数字?
选择位置,保留该点之前的所有数字,丢弃其余的。
截断是否四舍五入?
不会。截断完全忽略丢弃的数字。
截断和舍入的区别?
舍入会根据丢弃的数字更改保留的数字。截断只是删除数字。
截断总是趋向于零吗?
是的,当截断小数时,删除正数或负数的小数部分总是使其值更接近于零。
截断如何处理负数?
负数被截断后会趋向于零。例如,-3.9 截断为-3。
截断和取整有什么区别?
截断向零移动,而下限向负无穷移动。例如,-2.1 的下限为 -3,但截断 -2.1 会得到 -2。
截断和天花板有什么区别?
天花板走向正无穷大。截断 2.1 得到 2,但 2.1 的上限是 3。
能截断到小数位吗?
是的。您可以通过保留所需的小数位数并删除其余部分来截断到任何小数位。
如何截断到小数点后两位?
保留小数点后的前两位数字并删除其他所有数字。例如,5.6789 变为 5.67。
如何在 Python 中截断数字?
使用 math 模块中的 math.trunc() 函数将数字截断为零。
如何在 JavaScript 中截断数字?
使用 Math.trunc() 函数可以轻松删除数字的小数位。
如何在 Excel 中截断数字?
使用 TRUNC 函数,指定数字和所需的位数,例如 TRUNC(2.987, 2)。
截断与向下舍入相同吗?
不。对于负数,截断和向下舍入(下舍入)是不同的。截断 -2.9 得到 -2,向下舍入得到 -3。
整数可以用截断法吗?
是的,如果截断一个整数,它会保持完全相同,因为没有要删除的小数位。