How can I, without using formulas, show integers as integers, but decimals limited to a specific number of decimal places?
E.g. show:1
as 1
12
as 12
but 1.23456789
as 1.23
The number format 0.##
is close but it shows 1
as 1.
etc.
Answer. On the File tab, click Options. Click Advanced, and then under Editing options, select the Automatically insert a decimal point check box. In the Places box, enter a positive number four digits to the right of the decimal point or a negative number for digits to the left of the decimal point.
If acceptable, you may use the formula not in the sheet but as a condition for Conditional Formatting.
When your data is at A1:A4
as the sample on screenshot, we should create 2 Formatting Rules:
=MOD($A1,1) = 0
Applies to: =$A$1:$A$4
Format the number as no decimals from the format of this rule.=MOD($A1,1) <> 0
Applies to =$A$1:$A$4
& Format the number to show 2 decimals.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:
=IF(MOD(A1,1)=0,TEXT(A1,"0"),TEXT(A1,"0.00"))
A bit late to the Thread but I have a report which was calculating percentages to 7 decimal places, but the column also contains integers.
My conclusion was to use conditional formatting so if the Cell Contains a period/decimal point "." then to change the formatting to Number with 2 decimal places. This way if there isn't a period/decimal point then the values remain unedited.
If you would like to use the value as text you can use this (using A1 as the number):
=TEXT(A1,IF(MOD(A1,1)=0,"#","#.##"))
Explanation:IF(MOD(A1,1)=0
: This part checks if the number is a whole number with the modulo function.
"#","#.##"
: Use "#"
if the condition is true and "#.##"
if the condition is false. These are appropriate format options for integer and decimal numbers accordingly.
The number of hashes after the decimal in "#.##"
define the maximum precision, but it will only display as many as required e.g. 2.1 would not be "2.10", but "2.1" instead.
Alternatively: "#.00"
can be used to always pad with 0's, which would make "1.3" become "1.30".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With