4

I have a table of values with decimals and whole numbers. Some of the decimals have zeros two places after the decimal point (e.g. 0.60) or the two places after the decimal point are both zeros (e.g. 4.00).

How do I make sure any zeros are removed from after the decimal point? (So the aforementioned numbers would be 0.6 and 4.)

4 Answers 4

7

You need to define your own "number format". The format code you want to use is:

0.####


EDIT


The downside is you are always left with the trailing period, which cannot be handled by number formats alone. To remedy that, you can use the following function.

=SUBSTITUTE(TRIM(SUBSTITUTE(A1,"."," "))," ",".")

Results


Original  Formatted:  Trimmed:
Numbers:
===============================
17.000    17.         17
17.100    17.1        17.1
17.100    17.1        17.1
0.100     0.1         0.1


References


  1. Create a custom number format, Accessed 2014-06-25, <http://office.microsoft.com/en-ca/excel-help/create-a-custom-number-format-HP010342372.aspx>
2
  • It doesn't seem to work. All the decimals with zeros seem to appear in the format "$'25.50" but the function bar shows it as "25.5". What is wrong?
    – user112947
    Jun 25, 2014 at 20:25
  • 1
    That is exactly what I was looking for! Thanks a lot. For German Excel, keep in mind to change the function as follows: SUBSTITUTE() becomes WECHSELN() and TRIM() becomes GLÄTTEN(). Also instead of a comma, use a semicolon to separate function parameters. Dec 12, 2016 at 7:23
2

The General format will not show any trailing decimal zeros. Regardless of whether the number is entered manually or calculated, if the cell format is General, Excel will only show the decimals required to represent the number.

7
  • But it will show too many decimals when the number is 1.23456 and OP only wants two digits.
    – Floris
    Jun 25, 2014 at 21:01
  • @pnuts where do strings come in? Any formatting will fail if the values are strings, so what's the point of bringing this up?
    – teylyn
    Jun 25, 2014 at 21:40
  • 1
    @pnuts - the string tag was added by another user, not the OP, so I removed it again. The Q just states that some numbers HAVE two decimals, not that they WANT two decimals. Just nitpicking. This is not clear.
    – teylyn
    Jun 25, 2014 at 22:00
  • 1
    I took "have" to mean "want" - but accept it could be read differently.
    – Floris
    Jun 25, 2014 at 23:10
  • 1
    "General" has a problem: for small enough numbers, it will show the scientific format, e.g. 2.6532E-06 instead of 0.0000026532. For this particular question with up to 2 decimals, General works. But for the ahem, general, case (i.e. arbitrary precision), you want 0.########## (e.g. for up to 10 decimals). Jul 2, 2017 at 4:59
1

Please try:

=INT(A1*100)/100  

and copy down to suit, assuming your data is in ColumnA and that formatting is 'General'.


A comparison of various possibilities:

SO24417712 example

[It seems that for the accepted A to be correct the Q may be off topic (since @teylyn's solution would work also, is much simpler and requires no programming) - unless the objective is to convert to strings, which is not mentioned as a requirement.]

2
  • With what formatting of the cell? General, I presume?
    – Floris
    Jun 25, 2014 at 20:53
  • 1
    Add that to your answer and it gets my vote. This is the simplest answer that gives "at most two trailing decimals" and will trim zeros and the decimal point as needed.
    – Floris
    Jun 25, 2014 at 21:09
1

If you need the results in a simple way use this function with "General" formatting:

=ROUND(A1,2)

This will create the proper result

Note: In Portuguese version the name of the function is ARRED and you need to use semicolon to separate values as follows:

=ARRED(A1;2)

The values will be converted as follows:

Original            ROUND
--------------------------------
0.60                0.6
4.00                4
0                   0
7.75                7.75
0.016666667         0.02
5.833333333         5.83
2.673333333         2.67
699                 699

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.