77
16
I have numbers in cells in Excel. I want the numbers formatted so that if they have decimal places they show to a maximum of two, and if they have no decimal places it doesn't show any.
For example.
- 15 should be formatted as 15, NOT 15.00
- 14.3453453 should be formatted as 14.35
- 12.1 should be formatted as 12.1
- 0 should be formatted as 0
The closest custom format code I've come up with is 0.##
. Unfortunately this formats 15.00
as 15. (note the extra decimal point).
To further complicate the issue, the spreadsheet is a result of an export from SQL Server Reporting Services. So no macros are possible. Oh well, it looks like 0.##
is my best bet, and they can just live with the extra period.
4This answer deserves more upvotes. It handled the decimal point correctly without using conditional formatting. In my specific case, I want to show all decimal places, so I don't even need to modify the formula. – wilson – 2016-03-14T07:18:11.420
1
General
has the problem of going into scientific notation if the number has too many decimals, e.g.2.6532E-06
instead of0.0000026532
. – Dan Dascalescu – 2017-07-02T05:35:19.303+1 This was helpful for me in solving a specific problem of needing to display values of thousands of dollars (e.g. show $40,000 as $40k, and $10,500 as $10.5k), in the labels of a Pivot Table (where conditional formatting is not an option). Format code
$General\k
did it perfectly! – Dan Henderson – 2017-07-27T16:49:11.323