Excel number format to only show decimals when necessary

=IF(MOD(A1,1)=0,TEXT(A1,"0"),TEXT(A1,"0.00"))

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:

  1. Formula is: =MOD($A1,1) = 0 Applies to: =$A$1:$A$4 Format the number as no decimals from the format of this rule.
  2. Formula is: =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:

enter image description here