trunc函数使⽤⽅法_如何在Excel中使⽤TRUNC函数
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.
excel中round函数的使用方法
如果您要求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函数的优势在于它不会四舍五⼊,⽽只是将它们缩短到指定的⼩数位数。
trunc函数使⽤⽅法

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。