How to use the DECIMAL function
What is the DECIMAL function?
The DECIMAL function converts a text representation of a number in a given base into a decimal number.
Table of Contents
1. Introduction
How can I convert a number in the decimal numeral system to any another numeral system?
The BASE function converts a number into a text representation with a given radix (base).
Function syntax: BASE(number, radix, [min_length])
What is the decimal numeral system?
The decimal system is the numbers we use every day: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 It is based on the radix (base) of 10, there are 10 digits: 0 to 9. The value of each digit depends on its position or place value.
What is a radix (base)?
The radix or base refers to the number of unique digits in numeral systems that represents the numbers. Common radices are 2 (binary), 8 (octal), 10 (decimal), 16 (hexadecimal).
Changing the radix changes the digit representations but the numeric values are equivalent. The radix determines the inventory of digits used to express values.
What is a text representation?
The BASE function takes numbers as input, however, the output is a text string. This limits Excel's capabilities, for example performing arithmetic calculations to the converted text value are not possible unless you convert the text string back to the decimal system.
What base conversion functions does Excel have?
These functions convert from the decimal system to the binary, octal and hexadecimal systems.
DEC2BIN | DEC2OCT | DEC2HEX
These functions convert from the binary system to the decimal, octal and hexadecimal systems.
BIN2DEC | BIN2OCT | BIN2HEX
These functions convert from the octal system to the binary, decimal and hexadecimal systems.
OCT2DEC | OCT2BIN | OCT2HEX
These functions convert from the hexadecimal system to the binary, octal and decimal systems.
HEX2BIN | HEX2DEC | HEX2OCT
These functions are located in the "Engineering" category.
System | Base | Digits | Uses |
Decimal | Base 10 | 0-9 | General everyday use |
Octal | Base 8 | 0-7 | Older computer systems |
Binary | Base 2 | 0,1 | Modern computer processing |
Hexadecimal | Base 16 | 0-9, A-F | Computer memory addresses |
Is there a function that converts from the decimal system to any numeral system?
Yes, the BASE function lets you convert decimals.
The BASE function converts a number into a text representation with a given radix (base).
Function syntax: BASE(number, radix, [min_length])
2. Syntax
DECIMAL(text, radix)
text | Required. The text argument must be less than 256 characters. The Text argument can be alpha-numeric characters that are valid for the radix. Excel supports a Text argument greater than or equal to 0 and less than 2^53. |
radix | Required. Radix must be greater than or equal to 2 (binary, or base 2) and less than or equal to 36 (base 36). A radix greater than 10 use the numeric values 0-9 and the letters A-Z as needed. For example, base 16 (hexadecimal) uses 0-9 and A-F, and base 36 uses 0-9 and A-Z. |
3. Example 1
Convert binary number 101001 to its decimal representation?
Here are the arguments:
- number: 101001 (This is the number you want to convert from)
- radix: 2 which means binary. (This is the base of the number you convert from)
Formula in cell C5:
The formula returns 41 which is the decimal representation of binary number 101001. Lets calculate the values manually. In the binary system, each position represents a power of 2, while in the decimal system, each position represents a power of 10.
Start from the rightmost digit, assign a place value to each digit, with the rightmost digit having a place value of 2^0 = 1. The next digit to the left having a place value of 2^1 = 2, the next 2^2 = 4, and so on.
# | Binary | Power | Value | Multiply |
5 | 1 | =2^5 | 32 | 32 |
4 | 0 | =2^4 | 16 | 0 |
3 | 1 | =2^3 | 8 | 8 |
2 | 0 | =2^2 | 4 | 0 |
1 | 0 | =2^1 | 2 | 0 |
0 | 1 | =2^0 | 1 | 1 |
Total: | 41 |
Multiply each digit by its place value, then add up the products. The sum is 41 which matches the value in cell C5.
4. Example 2
Convert hexadecimal number FFFFFE to its decimal representation?
Here are the arguments:
- number: FFFFFE (This is the number you want to convert from)
- radix: 16 which means binary. (This is the base of the number you convert from)
Formula in cell C5:
The formula returns 16777214 which is the decimal representation of hexadecimal number FFFFFE. Lets calculate the values manually. We use the positional numeral system of the hexadecimal system where each position represents a power of 16. Each digit can have a value from 0 to 15 represented by 0-9 and A-F.
Start from the rightmost digit then assign a place value to each digit, with the rightmost digit having a place value of 16^0 = 1. The next digit to the left having a place value of 16^1 = 16, the next 16^2 = 256, and so on.
# | Hexadecimal | Decimal | Power | Value | Multiply |
5 | F | 15 | =16^5 | 1048576 | 15728640 |
4 | F | 15 | =16^4 | 65536 | 983040 |
3 | F | 15 | =16^3 | 4096 | 61440 |
2 | F | 15 | =16^2 | 256 | 3840 |
1 | F | 15 | =16^1 | 16 | 240 |
0 | E | 14 | =16^0 | 1 | 14 |
Total: | 16777214 |
Multiply each hexadecimal digit by its corresponding place value. Add up all the resulting products.
15,728,640 + 983,040 + 61,440 + 3,840 + 240 + 14 = 16,777,214 This value matches the calculated value in cell C5.
5. Example 3
Calculate the product of two hexadecimal numbers: 9F3 and 25A? Provide the result also in hexadecimal.
The image above shows the hexadecimal values specified in cells C2 and C3, the radix is in cell C4. The formula in cell C7 adds the hexadecimal values and returns a total or sum.
Formula in cell C7:
Actually, in detail the formula converts the hexadecimal values to decimal values then multiplies the decimal values to create a product. At last, the formula converts the product back to a hexadecimal value.
Explaining formula in cell C7
The formula in cell C7 must be entered as an array formula if you use an Excel version earlier than Excel 365. Here is how:
- Type or copy/paste the formula to the formula bar.
- Press and hold both CTRL and SHIFT keys
- Press Enter once.
- Release all keys.
The formula changes to this:
{=BASE(PRODUCT(DECIMAL(C2:C3,C4),C4)}
Don't enter the curly brackets yourself, they appear automatically if you followed the above steps.
Step 1 - Convert hexadecimal values to decimal values
The DECIMAL function converts a text representation of a number in a given base into a decimal number.
Function syntax: DECIMAL(text, radix)
DECIMAL(C2:C3,C4)
becomes
DECIMAL({"9F3";"25A"},16) and returns {2547;602}.
Step 2 - Calculate a total based on the decimal numbers
The PRODUCT function returns the product of the numbers given in the argument.
Function syntax: PRODUCT(number1, [number2], ... )
PRODUCT(DECIMAL(C2:C3,C4))
becomes
PRODUCT({2547;602}) and returns 1533294.
Step 3 - Convert decimal back to hexadecimal
BASE(PRODUCT(DECIMAL(C2:C3,C4)),C4)
becomes
BASE(1533294) and returns 17656E.
7. Function not working
DECIMAL returns the
- #NUM! error value if the number argument is larger than the radix. The image above shows number "ZZZZ" in cell B3 and radix 2 (binary) in cell C3.
- #VALUE! error value if the number of characters in the number argument is larger than 256. Cell B4 contains 300 characters.
7.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The DECIMAL function function requires arguments inside their constraints which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Functions in 'Math and trigonometry' category
The DECIMAL function function is one of 62 functions in the 'Math and trigonometry' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form