Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Engineering Calculations.

Engineering Calculations

by Allen Wyatt
(last updated January 4, 2014)

3

In an engineering environment, it is not unusual to need to "normalize" numbers in some manner. For instance, you may need to show numeric values normalized to multiples of 10^3, such that 7340 is expressed as 7.34 and 73400 is expressed as 73.4.

It is possible in Excel to use a custom number format to express information in scientific notation that will normalize the display of a number to a multiple of 10^3. To do this, you would follow these steps:

  1. Select the cells you want formatted.
  2. Display the Home tab of the ribbon.
  3. Click the small icon at the lower-right corner of the Number group. Excel displays the Format Cells dialog box.
  4. Make sure the Number tab is selected. (See Figure 1.)
  5. Figure 1. The Number tab of the Format Cells dialog box.

  6. In the list of format categories, choose Custom.
  7. In the Type box, enter ##0.0E+0 as your format. (This provides only one number to the right of the decimal place. If you want more, increase the number of zeros after the decimal place.)
  8. Click on OK.

Now, when you enter a number such as 7340 into the cell, Excel displays it as 7.3E+3. Because of the way the cell format was entered, the portion after the E will always be a multiple of 3.

This is fine and good, but what if you want just the 7.3 in the cell, and then a metric prefix with a unit in an adjoining cell, such as kilograms? This is a bit more complex, but it can be done using formulas. For instance, let's assume you have your original number in cell A2, you wanted the normalized number in cell B2, and the metic prefix and unit name in cell C2. All you would need to do is enter the following formula in cell B2:

=IF(OR(A2>=1,A2<=-1),SIGN(A2)*(ABS(A2)/(10^(3*INT(LOG(ABS(A2))/3)))),
IF(A2=0,0,SIGN(A2)*(ABS(A2)*10^(-3*INT(LOG(ABS(A2))/3)))))

Assuming the units you are working with are an imaginary unit called a foo, in cell C2 you would use a different formula, as follows:

=IF(OR(A2>=1, A2<=-1),CHOOSE(INT(LOG(ABS(A2))/3)+1, "Foos", "Kilofoos",
"Megafoos", "Gigafoos", "Terafoos", "Petafoos", "Exafoos"),
IF(A2=0,"",CHOOSE(INT(-LOG(ABS(A2))/3)+1, "Millifoos", "Microfoos",
"Nanofoos", "Picofoos", "Femtofoos", "Attofoos")))

These formulas may seem a bit long, and they are. However, they will work for any number between approximately -9.99999E-18 to 9.99999E+20. For instance, if you put the number .000125 in cell A2, then cell B2 will contain 125 and cell C2 would contain Millifoos.

If you prefer to not use longer formulas such as these in your workbooks, you can develop a couple of VBA functions to do the trick. The following function, MySciNum, returns a normalized number. Thus, you would use =MySciNum(A2) in cell B2 to get the same results as noted above:

Function MySciNum(BaseNum As Double) As Double
    Select Case BaseNum
        Case Is >= 1
            While Abs(BaseNum) > 1000
                BaseNum = BaseNum / 1000
            Wend
        Case 0
            'Do nothing
        Case Else
            While Abs(BaseNum) < 1
                BaseNum = BaseNum * 1000
            Wend
    End Select
    MySciNum = BaseNum
End Function

This function only returns a number. To return the units with the appropriate metric prefix, you would use the following function. All you need to do is pass it the cell reference and the name of a single unit. For instance, you could use =MySciPre(A2, "foo"). The macro is as follows:

Function MySciPre(BaseNum As Double, Unit As String) As String
    Dim OrigNum As Double
    Dim Pref As Integer
    Dim Temp As String

    Pref = 0
    OrigNum = BaseNum
    Select Case BaseNum
        Case Is >= 1
            While Abs(BaseNum) > 1000
                BaseNum = BaseNum / 1000
                Pref = Pref + 1
            Wend
        Case 0
            Pref = 99
        Case Else
            While Abs(BaseNum) < 1
                BaseNum = BaseNum * 1000
                Pref = Pref - 1
            Wend
    End Select

    Select Case Pref
        Case -6
            Temp = "atto" & Unit
        Case -5
            Temp = "femto" & Unit
        Case -4
            Temp = "pico" & Unit
        Case -3
            Temp = "nano" & Unit
        Case -2
            Temp = "micro" & Unit
        Case -1
            Temp = "milli" & Unit
        Case 0
            Temp = Unit
        Case 1
            Temp = "kilo" & Unit
        Case 2
            Temp = "mega" & Unit
        Case 3
            Temp = "giga" & Unit
        Case 4
            Temp = "tera" & Unit
        Case 5
            Temp = "peta" & Unit
        Case 6
            Temp = "exa" & Unit
        Case Else
            Temp = ""
    End Select

    If Len(Temp) > 0 Then
        Temp = LCase(Temp)
        Temp = UCase(Left(Temp, 1)) & Mid(Temp, 2)
        If Abs(OrigNum) <> 1 Then Temp = Temp & "s"
    End If

    MySciPre = Temp
End Function

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12874) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Engineering Calculations.

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

Specifying a Table of Contents Entry

If you need to create a specialized table of contents, you need to know how to add TOC entries to your document. It's easy to ...

Discover More

Sorting or Filtering by Conditional Format Results

Conditional formatting is a great feature in Excel. Unfortunately, you can't sort or filter by the results of that ...

Discover More

Determining the Number of Paragraphs in a Document

When using a macro to process a document in some way, you often need to know the number of paragraphs in the document. (This ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Macros Run Slower in Newer Excel?

If you run a macro you used in an older version of Excel on a newer system, it may seem like the macro runs slower. Here are ...

Discover More

Removing Pictures for a Worksheet in VBA

Excel allows you to add pictures to your worksheet, even within a macro. However, you might have a bit harder time figuring ...

Discover More

Replacing and Converting in a Macro

When you use a macro to process data you always run the risk of making that data unusable by Excel. This is especially true ...

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}] 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 seven less than 7?

2014-01-10 16:08:09

Dennis Costello

What neither the tip nor the Excel help explained is the significance of the custom format string - and it turns out to be interesting.

"Scientific Notation" has a sign (+ by default), then some number between 1 <= x < 10 with as many digits after the decimal as you wish (the mantissa), then an "E", then a signed integer (the exponent) - for instance 12,000 is written as 1.20E+4. The "standard" Excel custom format 0.00E+00 captures this, giving two digits after the decimal and at least two digits in the exponent.

"Engineering Notation" is the same, but the powers of 10 must be multiples of 3, so the value before the E is in the range 1 <= x < 1000. Excel's "standard" custom format for this is ##0.0E+0.

Why? It's the leading "#"s. The say that up to 3 leading digits are allowed in the mantissa, and thus its value could be anything < 1000.

Here's the interesting part. There are other possible formats. For instance, the values 1,200, 12,000, 120,000, etc are shown in table below, in the formats in the first row:

0.0E+0 #0.0E+0 ##0.0E+0 ###0.0E+0
1.2E+3 12.0E+2 1.2E+3 1200.0E+0
1.2E+4 1.2E+4 12.0E+3 1.2E+4
1.2E+5 12.0E+4 120.0E+3 12.0E+4
1.2E+6 1.2E+6 1.2E+6 120.0E+4
1.2E+7 12.0E+6 12.0E+6 1200.0E+4

In other words, the first format shown is scientific notation. The second one shown has a mantissa between 1 and 100, and the exponent always even. The third one is engineering notation. The last column has a mantissa between 1 and 10,000, and the exponent is always a multiple of 4.

Not sure why anyone would want to see numbers broken out this way, but as I said it's interesting that Excel recognizes and properly handles these odd cases.


2014-01-07 14:06:42

Bryan

Hrm, MySciPre is pretty clever, but in 4 years of (chemical) engineering classes I never needed anything like it. I never cared what order of magnitude the number was as long as it was the correct units. However, I can see the macros being useful in creating a human-readable output from a widely varying input. Like an auto-scaler.

@Barry: Usually I agree with you, but I always find it better to keep the units separated from the numbers. Plus I like to (and in many cases, have to) keep the original number and units somewhere anyway, so I can't/shouldn't just use formatting to keep the original and converted units in the same cell. Also, putting the units in another cell adds flexibility if, say, you need to change the output units at a later date. I hadn't discovered macros in college, but I used drop downs and IF formulas to allow unit converting on the fly, which wouldn't be possible if the units were hidden within the formatting.


2014-01-04 07:18:24

Barry Fitzpatrick

There is a fundamental problem with the macros in that the function has to be in another cell in the workbook/worksheet, and you cannot use the value in the cell for subsequent calculations.

The way around this is to use the custom number formats, although this only seems to work for numbers greater than 1.

So for the number 73400 as "73.4 Kilo-units" use the macro to set the format to "0.0," Kilo-units"
for the number 73400000 as "73.4 Mega-units" get the macro to set the format to "0.0,," Mega-units"
for the number 73400000000 as "73.4 Giga-units" get the macro to set the format to "0.0,,," Giga-units"
and so on for tera, peta, and exa adding an extra "," and changing the text accordingly.
This preserves the underlying value, which can be used in other calculations.

If additional digits after the decimal point are required then use 0.00 for two digits, 0.000 for three digits etc etc, and for no digits after the decimal use "0" before the commas.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu 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.