简体   繁体   English

Excel - 删除单元格中的特定小数

[英]Excel - Remove a specific decimal in a cell

I am having difficulty removing just the last decimal from my cells.我很难从我的单元格中删除最后一个小数。 Any suggestions?有什么建议么?

Example: 0101.29.00.90 to 0101.29.0090示例:0101.29.00.90 到 0101.29.0090

Assume A1: 0101.29.00.90假设 A1: 0101.29.00.90

To remove the last decimal from cell, if the no of decimal does not fixed, in B1 enter formula:要从单元格中删除最后一个小数,如果小数不固定,在 B1 中输入公式:

=SUBSTITUTE(A1,".","",LEN(A1)-LEN(SUBSTITUTE(A1,".","")))

To remove the last decimal from cell, if the decimal fixed in 3 no, B1 formula can be shortened to:要从单元格中删除最后一个小数,如果小数固定在 3 没有,B1 公式可以缩短为:

=SUBSTITUTE(A1,".","",3)

The result is: 0101.29.0090结果是: 0101.29.0090

Here is a more universal approach:这是一种更通用的方法:

Suppose your data is in cell A1 , in cell B1 enter the following array formula :假设您的数据在单元格A1中,在单元格B1中输入以下数组公式

=REPLACE(A1,MAX(IFERROR(FIND(".",A1,ROW($A$1:INDEX($A:$A,LEN(A1)))),0)),1,"")

You MUST press Ctrl + Shift + Enter upon finishing the formula in the formula bar otherwise it will not function correctly.完成公式栏中的公式后,您必须Ctrl + Shift + Enter ,否则将无法正确 function。 Then you can simply drag the formula down to apply across.然后,您只需将公式向下拖动即可应用。

The logic is to use FIND function to find the position of each dot .逻辑是使用FIND function 找到每个点的 position . within the string, then use MAX+IFERROR functions to return the largest value ie the position of the last dot .在字符串中,然后使用MAX+IFERROR函数返回最大值,即最后一个点的 position . , then use REPLACE function to replace the last dot . ,然后使用REPLACE function 替换最后一个点. with blank "" .用空白""

Here is some testing results:以下是一些测试结果:

| Sample Data     | Result         |
|-----------------|----------------|
| 0101.29.00.90   | 0101.29.0090   |
| 1.2.3.4.5.6.7.8 | 1.2.3.4.5.6.78 |
| 000.111.222.3   | 000.111.2223   |
| 4.3.2.01        | 4.3.201        |

You need to use the SUBSTITUTE function.您需要使用SUBSTITUTE function。

SUBSTITUTE(text, old_text, new_text, [instance_num])替代(文本,旧文本,新文本,[instance_num])

The SUBSTITUTE function syntax has the following arguments: SUBSTITUTE function 语法具有以下 arguments:

Text Required .文本必填 The text or the reference to a cell containing text for which you want to substitute characters.文本或对包含要替换字符的文本的单元格的引用。

Old_text Required . Old_text必需 The text you want to replace.要替换的文本。

New_text Required .新文本必需 The text you want to replace old_text with.您要替换 old_text 的文本。

Instance_num Optional . Instance_num可选 Specifies which occurrence of old_text you want to replace with new_text.指定要用 new_text 替换哪个 old_text 出现。 If you specify instance_num, only that instance of old_text is replaced.如果您指定 instance_num,则仅替换 old_text 的该实例。 Otherwise, every occurrence of old_text in text is changed to new_text.否则,文本中每次出现 old_text 都会更改为 new_text。


Last Option is not optional for your problem.最后一个选项对于您的问题不是可选的。 For example, use the below formula例如,使用以下公式

=SUBSTITUTE(A1,".","",3)

assuming that source data is in cell A1.假设源数据在单元格 A1 中。

It will replace third dot with null string and you'll have desired solution.它将用 null 字符串替换第三个点,您将获得所需的解决方案。

ie 0101.29.00.90 to 0101.29.0090即 0101.29.00.90 到 0101.29.0090

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM