(custom format) If number is INTEGER, don't show decimals, but...

roc_on_the_rocks

Board Regular
Joined
Jun 6, 2009
Messages
175
Office Version
  1. 365
Platform
  1. Windows
How to CUSTOM FORMAT a cell... if number is INTEGER, don't show decimals (e.g.: 24), but if fractional, show first decimal point (e.g.: 24.5)?

Following this example, I don't want to have '24.0', but '24' instead.

I appreciate the help!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I think the closest you'll get is to custom format as 0.# which will always show the decimal point, but not a non-zero decimal
 
Upvote 0
This is not beautiful but i think it works

Assuming formatting A1

1. First format A1 as Number with 1 decimal place

2. Go to Conditional Formatting
New Rule
Use a formula to.. (the last option)

and insert this formula
=SEARCH(".0",TEXT(A1,"0.0"))

Click the Format button
and pick Number with 0 decimal places

Ok, Ok

done

Now you can use the Format Painter to apply the format to other cells.

HTH

M.
 
Upvote 0
Solution
Marcelo, this is very ingenious, it works great! This trick is a keeper. Muito obrigado!

shg4421, thanks too, you got me closer.
 
Upvote 0
Roc,

Thanks very much for your kind words.
(and specially for the "Muito Obrigado" :))

All the best

M.
 
Upvote 0

Forum statistics

Threads
1,214,638
Messages
6,120,676
Members
448,977
Latest member
moonlight6

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top