Excel数字格式仅在必要时显示小数 [英] Excel number format to only show decimals when necessary
问题描述
在不使用公式的情况下,我怎么能将整数显示为整数,但是小数限制为特定的小数位数.
How can I, without using formulas, show integers as integers, but decimals limited to a specific number of decimal places.
例如展示:
1
表示为1
,12
表示为12
,而1.23456789
表示为1.23
?
e.g. show:
1
as 1
, 12
as 12
, but 1.23456789
as 1.23
?
数字格式0.##
接近,但将1
显示为1.
等.
The number format 0.##
is close but shows 1
as 1.
etc.
推荐答案
如果可以接受,则可以不在工作表中使用该公式,而可以作为条件格式的条件.
If acceptable, you may use the formula not in the sheet but as a condition for Conditional Formatting.
当您的数据位于A1:A4
作为屏幕截图中的示例时,我们应该创建2条格式化规则:
When your data is at A1:A4
as the sample on screenshot, we should create 2 Formatting Rules:
- 公式为:
=MOD($A1,1) = 0
适用于:=$A$1:$A$4
从该规则的格式开始,将数字设置为不带小数的形式. - 公式为:
=MOD($A1,1) <> 0
适用于=$A$1:$A$4
&格式化数字以显示2位小数.
- Formula is:
=MOD($A1,1) = 0
Applies to:=$A$1:$A$4
Format the number as no decimals from the format of this rule. - Formula is:
=MOD($A1,1) <> 0
Applies to=$A$1:$A$4
& Format the number to show 2 decimals.
实际上,第二个条件是可选的.您可以将整个列的格式设置为2个小数,并使用第一个规则设置条件格式,这样只有整数将没有小数.
Actually the 2nd condition is optional. You may format the whole column with 2 decimals and conditional format with the first rule so only the integers will have no decimals.
请查看我的示例屏幕截图:
Please see my sample screenshot:
这篇关于Excel数字格式仅在必要时显示小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!