首页 > 编程知识 正文

trunc函数 excel,excel trunc函数怎么用

时间:2023-05-05 05:36:40 阅读:260855 作者:2579

trunc函数使用方法

There are a variety of ways in Excel to remove decimal points and shortening number values. In this article, we explain how to use the TRUNC function and what makes it different from other techniques.

Excel中有多种删除小数点和缩短数字值的方法。 在本文中,我们解释了如何使用TRUNC函数以及它与其他技术的不同之处。

什么是TRUNC函数? (What Is the TRUNC Function?)

The TRUNC function truncates a number to a specified number of decimal places. The key factor that makes TRUNC different from other functions that remove decimal places is that the TRUNC function does not round values. If you use TRUNC to remove all the decimals from the value 4.68, the result is 4.

TRUNC函数将数字截断为指定的小数位数。 使TRUNC与其他删除小数位的函数不同的关键因素是TRUNC函数不会舍入值。 如果使用TRUNC从值4.68中删除所有小数,则结果为4。

The TRUNC function requires two pieces of information:

TRUNC函数需要两条信息:

=TRUNC(number, [digits])

The number is the value you want to truncate. Digits are the number of numerals you want to truncate the value to. The digits portion is optional, and if not answered, TRUNC will remove all decimal places.

该数字是您要截断的值。 数字是您要将值截断到的数字数量。 数字部分是可选的,如果未回答,则TRUNC将删除所有小数位。

如何使用TRUNC功能 (How to Use the TRUNC Function)

Let’s look at examples of the TRUNC function with some sample data. The below example uses the following TRUNC function.

让我们看一下带有一些样本数据的TRUNC函数的示例。 下面的示例使用以下TRUNC函数。

=TRUNC(A2)

If you do not specify how many digits to truncate, all decimal places will be removed.

如果未指定截断位数,则将删除所有小数位。

You can see with the value in cell A2 that the TRUNC function does not apply any rounding. It simply truncates the number to 411.

从单元格A2中的值可以看到TRUNC函数不应用任何舍入。 它只是将数字截断为411。

Let’s see another example. This time we will reduce the values to two decimal places.

让我们来看另一个例子。 这次我们将值减少到两位小数。

=TRUNC(A2,2)

The TRUNC function will not display extra decimals if you ask it to show more than you have.

如果您要求TRUNC函数显示的小数位数过多,将不会显示该位数。

Take the following example, and let’s truncate it to two decimal places.

以下面的示例为例,让我们将其截断为两位小数。

=TRUNC(A2,2)

The value in cell A4 is reduced to two decimal places, but the values in A2 and A3 stay as they are because they have less than two decimal places already.

单元格A4中的值减少到两位小数,但A2和A3中的值保持原样,因为它们已经少于两位小数了。

If you want to display the two decimals, the cells will need to be formatted to be forced to show them.

如果要显示两个小数,则需要格式化单元格以强制显示它们。

从日期时间戳中删除时间 (Remove the Time from a Date-Time Stamp)

A useful example of TRUNC is to remove the time from a date and time stamp in Excel.

TRUNC的一个有用示例是从Excel中的日期和时间戳中删除时间。

Imagine having the following date and time stamps, but we just want the date in a column for analysis.

假设有以下日期和时间戳,但我们只希望将日期放在一列中进行分析。

The following formula will work to remove the time.

下面的公式将节省时间。

=TRUNC(A2)

Although the time is removed, the resulting cells will still need to be formatted as a date only.

尽管删除了时间,但仍然需要将生成的单元格仅格式化为日期。

使用TRUNC缩短数字 (Use TRUNC to Shorten Numbers)

This is a rare technique, but it is worth knowing that the TRUNC function will also accept negative numbers for the digits argument. When you use a negative number, the formula truncates the numbers to the left of the decimal point. However, it does not change the number of digits. It will replace them with zeroes.

这是一种罕见的技术,但值得一提的是,TRUNC函数还将为digits参数接受负数。 当您使用负数时,该公式将截断小数点左边的数字。 但是,它不会更改位数。 它将用零代替它们。

Let’s look at the following example.

让我们看下面的例子。

=TRUNC(A2,-1)

You can see in each example that zero was used to replace the number that was removed from the left of the decimal point.

您可以在每个示例中看到用零代替从小数点左侧删除的数字。

There are multiple ways in Excel to remove decimal places, however, most of these will apply a rounding of some nature. The strength of the TRUNC function is that it does not round values and simply shortens them to the specified decimal place amount.

Excel中有多种删除小数位的方法,但是,其中大多数将采用某种舍入方式。 TRUNC函数的优势在于它不会四舍五入,而只是将它们缩短到指定的小数位数。

翻译自: https://www.howtogeek.com/462168/how-to-use-the-trunc-function-in-excel/

trunc函数使用方法

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。