+ Reply to Thread
Results 1 to 5 of 5

Custom format - display n decimal places except when there are fewer decimal places

  1. #1
    Registered User
    Join Date
    07-02-2017
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    7

    Custom format - display n decimal places except when there are fewer decimal places

    In Excel we can customize the number of decimal places to display. For example if we set it to 2:

    2.2556 > 2.26
    20 > 20.00
    7.1 > 7.10

    In practice, this is highly undesirable. The most common requirement (in office settings at least) is to display as many decimal places as there is, but not exceeding a limit. For example, if that limit is 2, we should have:
    2.2556 > 2.26
    20 > 20
    7.1 > 7.1

    Because nobody wants to see the extra zeros when it's taken for granted that they are there (for the case of 20 and 7.1 above)

    Note: I know the "General" format tends to keep whatever you typed, so case 2 and 3 above would be fine, but for case 1 (2.2556 I would have to manually format it to 2 decimal places)


    Thanks!
    Interpreter Platform
    https://www.freelensia.com

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2503 (Windows 11 Home 24H2 64-bit)
    Posts
    90,476

    Re: Custom format - display n decimal places except when there are fewer decimal places

    In practice, this is highly undesirable.
    I disagree - it is far easier to compare values scanning down a column that have the same number of decimal places than not.

    I don't think what you want can be done without VBA, unless the values in question are the result of a formula. I think this is the closest you will get with custom number formatting:

    0.#0

    This leaves an orphaned decimal point:

    0.##

    However, if you use 0.## combined with a conditional formatting rule:

    =INT(A1)=A1

    then you can force numbers with no decimal places to show as General format.
    Last edited by AliGW; 06-26-2022 at 06:18 AM. Reason: Workbook attached.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Custom format - display n decimal places except when there are fewer decimal places

    Use this as the custom format:

    0.##
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  4. #4
    Registered User
    Join Date
    07-02-2017
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    7

    Re: Custom format - display n decimal places except when there are fewer decimal places

    Thanks both of your for the solutions. Neither solve my problem perfectly but I appreciate the input.

  5. #5
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,411

    Re: Custom format - display n decimal places except when there are fewer decimal places

    You can pre-format the cells to show only integer values (i.e. set number of decimal places to zero on the Number tab), and then use Conditional Formatting to set the Number format to General using the rule:

    =INT(A1)<>A1

    for the range of cells that you want this to apply to (assumed to be in A1 here). Thus, integer values will display with no decimal point, but fractional values will show where appropriate.

    Hope this helps.

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adusting decimal places based on greatest number of places in a series
    By anelson87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2022, 01:05 PM
  2. [SOLVED] Display 2 decimal places
    By Simply_Me in forum Excel General
    Replies: 6
    Last Post: 04-30-2019, 12:34 PM
  3. [SOLVED] Calculating decimal places in a non decimal format (ie sixes not tens)
    By Mike Brewer in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-07-2013, 08:58 AM
  4. Display value in textbox format decimal places
    By alex3867 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2007, 07:20 AM
  5. How many decimal places can a cell display?
    By Spaz in forum Excel General
    Replies: 9
    Last Post: 04-03-2006, 03:40 PM
  6. [SOLVED] How many decimal places can a cell display?
    By Spaz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-03-2006, 03:40 PM
  7. Cannot custom format decimal places
    By rogue_phoenix in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-21-2005, 03:56 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1