Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Sorting Decimal Values.

# Sorting Decimal Values

by Allen Wyatt
(last updated June 23, 2015)

Bob often needs to construct tables that are keyed to titles in government regulations. The numbering of the regulations is in decimal form and this creates problems when he tries to sort them in order. Examples are 820.20, 820.25, 820.200, 820.250. Bob enters these as text, but they still come out sorted in a manner that he does not want. In all cases, Excel drops off the trailing zeros and sees "820.20" and "820.200" as the same thing; Bob is wondering what he can do.

First of all, it should be pointed out that if Excel is dropping the trailing zeroes, then the cells are not formatted as text. You'll need to format the cells as text before you put anything in them, or else you'll need to precede the entry with an apostrophe. In either case, the trailing zeroes should remain in place.

Another way to force the entries to text is to modify them in some way. For instance, you could enter "Reg 820.200" instead of "820.200." Or you could replace the period after the 820 with a space or a dash. Any of these methods, and many more, would force the entry to be treated as text.

Even if you force the entry of information to text, that still won't solve the sorting problem, however. Sort a bunch of these cells, and they will still come out in an order you don't want:

```820.190
820.2
820.20
820.200
820.201
820.25
820.27
```

The reason is because the sorting is done from left to right, and in this scheme ".20" will always come before ".200" which always comes before ".25." The only way around this is to modify the structure of the numbers so that (in this case) there are always three digits after the decimal point:

```820.002
820.020
820.025
820.027
820.190
820.200
820.201
```

While this gives the proper sorting order, it does havoc to the original intent: to match the numbering used in the governmental numbering system. If you want to be true to that numbering scheme, the only solution is to use three columns for your numbering. The first column would be the government numbers, entered as text. The second column would be the part those numbers to the left of the decimal point, derived with a formula:

```=LEFT(A1,FIND(".",A1)-1)
```

The third column would be the portion to the right of the decimal point, derived with this formula:

```=RIGHT(A1,LEN(A1)-FIND(".",A1))
```

With the three columns in place, you can then do your sorting based on the contents of the second and third columns. After the numbers are sorted, you can hide the second and third columns, as desired.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3836) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Sorting Decimal Values.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Deleting Paragraph Borders

Got a document that has a border around some paragraphs? Here's how you can get rid of the border using the tools on the Home ...

Discover More

Setting Fraction Bar Overhang Spacing in the Equation Editor

The Equation Editor is a great tool for easily creating fancy-looking equations in your document. One setting you can control ...

Discover More

Randomly Resetting Numbering

Have you ever been frustrated by the automatic numbering feature in Word? You are not alone. Fortunately, there are a few ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

Automatically Sorting as You Enter Information

When entering information into a worksheet, you may want it to always be in a correctly sorted order. Excel allows you to ...

Discover More

Incomplete and Corrupt Sorting

Using the sorting tools, on the toolbar, may result in some unwanted results, such as jumbled data. If this happens to you, ...

Discover More

Sorting by Five Columns

Excel allows you to sort but up to three columns, but you may want to sort by more than that. This tip provides ways you can ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. Youâ€™ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 9 + 8?

2014-11-25 11:27:48

Jaycee

I am also working with government documents that have paragraphs separated with decimals. I need to sort lists with multiple decimals. Example
1.3.4.12
1.3.4.2
1.4.3.2
etc
There is not always the same number of decimals. Is there a way to build a form to accomplish this so that any user will get the right answer without using the text to columns feature?

2013-03-07 12:22:51

Luenda

I have two columns of values that both totalled \$33,420,086.94

I used the format function for values not equal to 0 to be highlighted red

When I checked the totals, there was no decimal places more than two in my entries

I copied and past special values the difference and got a value of 2.98023223876953E-08
When I increased the difference cell decimal place column, the results was
.0000000298023223876953

In the difference cell when I increase the number of decimal places to about 80 decimal places, there were zeros right through

Can you advise me as to how the difference column is coming up with a difference?