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: Using an Exact Number of Digits.

Using an Exact Number of Digits

Written by Allen Wyatt (last updated December 1, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003


Henk asked if there is a way in Excel to display a number using six digits, independent of the placement of the decimal point. For instance, 0.1 would be displayed as 0.10000, 200 would be displayed as 200.000, and 25000 would be displayed as 25000.0.

Unfortunately, there is no formatting that will do the trick; all display formatting seems to be dependent on the position of the decimal point. You can format a display for a specific number of digits after the decimal point, but that number of digits will be used regardless of how many digits appear before the decimal point.

Several ExcelTips subscribers came up with suggestions that involve using formulas to display the number as desired. For instance, the following formula will display the value in A1 using six digits:

=FIXED(A1,IF(ABS(A1)<1,5,5-INT(LOG(ABS(A1)))),TRUE)

Other readers provided formulas that relied on converting the number to a text string and displaying it as such. Converting a number to its textual equivalent, however, has the distinct drawback of no longer being able to use the number in other formulas. (Remember—it is text at this point, not a number.) The above formula does not have that limitation.

If you wanted to, you could also use a macro to set the formatting within a cell that contains a value. The advantage to such a macro is that you don't have to use a cell for a formula, as shown above. The drawback to a macro is that you need to remember to run it on the cells whenever values within them change. The following macro is an example of such an approach:

Sub SetFigures()
    Dim iDecimals As Integer
    Dim bCommas As Boolean
    Dim sFormat As String
    Dim CellRange As Range
    Dim TestCell As Range

    bCommas = False 'Change as desired

    Set CellRange = Selection
    For Each TestCell In CellRange
        If Abs(TestCell.Value) < 1 Then
            iDecimals = 5
        Else
            iDecimals = 5 - Int(Log(Abs(TestCell.Value)) / Log(10#))
        End If

        sFormat = "0"
        If bCommas Then sFormat = "#,##0"
        If iDecimals < 0 Then sFormat = "General"
        If iDecimals > 0 Then sFormat = sFormat & _
          "." & String(iDecimals, "0")

        TestCell.NumberFormat = sFormat
    Next TestCell
End Sub

In order to use the macro, simply select the cells you want to format, then execute it. Each cell in the range you selected is set to display six digits, unless the number in the cell is too large or too small.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (1933) 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: Using an Exact Number of Digits.

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

Determining the Hour of the Day

Need to know the current hour of the day? You can derive the information in your macros by using the Hour function, as ...

Discover More

Correcting a Capital Mistake

As you are entering data in a worksheet, Excel can monitor what you type and make corrections for common mistakes. One ...

Discover More

One Change Affects Everything

Have you ever made one formatting change in your document, only to see that change applied to all the paragraphs in the ...

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!

More ExcelTips (menu)

Specifying Superscript Text

Applying different formatting to the text within a cell can seem a bit confusing. This is certainly the case when it ...

Discover More

Understanding Number Formatting Codes

When creating custom formats, you can employ a wide range of codes to define your formatting pattern. This tip focuses on ...

Discover More

Wrapping Your Text

Want to see all the text that is in a cell, even if it is quite a bit? You need to make sure that text wrapping is turned ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 six minus 4?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.