+ Reply to Thread
Results 1 to 9 of 9

Custom format to show decimals only when needed

  1. #1
    Registered User
    Join Date
    05-16-2014
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Custom format to show decimals only when needed

    Hey guys,

    I have a sheet with some numbers that have different decimals, e.g.
    5,90625
    14,625
    10,125
    0,0525
    0,5125
    0
    0,495
    0,185

    Now I want to format these cells so that the cells with a value (no zero) have 2 decimals, but zero still shows only as 0. When formatting to a number with two decimals I get 0,00 which I do not want. I have tried the custom format [>0]#,##;[=0]0 However, this changes 0,5125 to ,51 where I want it to show 0,51. The zeros do show as just 0 and other values get 2 decimals, so I'm close, I just cant figure out why the 0 dissappears. Does anyone have any thoughts?

    Cheers

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,032

    Re: Custom format to show decimals only when needed

    Try this custom format:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Never use Merged Cells in Excel

  3. #3
    Registered User
    Join Date
    05-16-2014
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Custom format to show decimals only when needed

    Hey Zbor,

    Unfortunately, excel gives me the error 'cannot use the number format you typed' This might be due to comma, semi-column conversion for different excel versions, when I replace the commas with semicolumns (#.##;-#.##;0;@) excel exepts it but values between 0 and 1 are now blank, and there are no decimals. When I replace the periods with commas (#,##;-#,##;0;@) The result is the same as I previously had, the zero before the decimals is left out, rest is good.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,371

    Re: Custom format to show decimals only when needed

    This would probably be worth studying: http://office.microsoft.com/en-us/ma...902.aspx?CTT=1 This file explains that " If the format code contains only number signs (#) to the left of the decimal point, numbers with a value of less than 1 begin with the decimal point, not with a zero followed by a decimal point." I think what you want is to replace the "#"s before the decimal points with "0"s in your format code.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    05-16-2014
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Custom format to show decimals only when needed

    Little update: [=0]0;0,## now gives me almost correct values, the zeros show, I now get 0,51 However, whole numbers now get a comma but no decimals (e.g. 14 shows as 14,) Anyone have any thoughts on how to fix this last little issue? Rest is working fine, even though I don't quite understand why, for example I thought this code would change 1,6875 to 0,69 (because the 0 is hardcoded in the code) Trial and error ftw I guess.

    Edit: Just missed your reaction before posting this MrShorty, it explains the part I didnt understand

  6. #6
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Custom format to show decimals only when needed

    This might work for you:

    #0.#0;-#0.#0;0
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,371

    Re: Custom format to show decimals only when needed

    However, whole numbers now get a comma but no decimals (e.g. 14 shows as 14,) Anyone have any thoughts on how to fix this last little issue?
    I have not found a good way around this issue. It seems that, if you put any kind of placeholder (?, #, or 0) to the right of the decimal point, Excel decides to include the decimal point -- even for whole numbers. I have not found a good way (using number formatting anyway) to get a different format (specifically to get rid of the decimal point) for integers vs. real numbers.

    If you are willing to do something with formulas, you can use the =TEXT() function to get numbers into various formats. Because you can nest other Excel functions inside of the TEXT() function, you can get greater control over the displayed format of the numbers. The main caution with this is to recognize that the TEXT() function also converts numbers to text strings, which often changes the way they behave in the spreadsheet (sort order is different for example).

  8. #8
    Registered User
    Join Date
    05-16-2014
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Custom format to show decimals only when needed

    Thanks for your replies guys. MrShorty, too bad they haven't fixed this, seems like a perfect solution is not possible then. As my cells are already fairly complicated (nested VLOOKUPS and IFS etc.) Nesting them in TEXT() would make it a bit too complicated newdoverman, thanks for your input, I have altered your suggestion a bit to 0,#0;-0,#0;0 it now shows zero's only, max 2 decimals, and round numbers get one zero (e.g. 14 shows as 14,0). An accaptable solution for me, not as ugly as a lot of decimals and single comma's showing, thanks for your help.

  9. #9
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Custom format to show decimals only when needed

    You're welcome. Thanks for the feedback.

+ 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. [SOLVED] 0;-0;;@ - format to show as two decimals places
    By johnmitch38 in forum Excel General
    Replies: 3
    Last Post: 09-05-2012, 09:34 AM
  2. custom cell format needed
    By cosmicgrooves in forum Excel General
    Replies: 5
    Last Post: 01-26-2008, 06:17 PM
  3. [SOLVED] Custom percent format needed
    By Will Fleenor in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. Custom percent format needed
    By Will Fleenor in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. [SOLVED] Custom percent format needed
    By Will Fleenor in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

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