N function
The N function in Excel is used to convert a value to a number. It is primarily used to return the numeric value of a cell or expression. If the value is already a number, it returns that number; if it is text or an error, it returns 0. The function can also be used to extract the numeric value from certain types of data, such as dates.
Syntax:
N(value)
Arguments:
- value: The value or expression you want to convert to a number. This can be a cell reference, formula, or direct value.
Example:
Example 1: Convert a number to a number
- Data in A1:
10 - Formula:
=N(A1) - Result:
10(since A1 contains a number, the function returns the same number).
Example 2: Convert a date to a number
- Data in B1:
01/01/2025(date format) - Formula:
=N(B1) - Result:
44616(Excel stores dates as serial numbers, so the date01/01/2025is returned as44616).
Example 3: Convert text to a number
- Data in C1:
"Hello" - Formula:
=N(C1) - Result:
0(since"Hello"is text and not a number, the function returns0).
Example 4: Convert a logical value to a number
- Data in D1:
TRUE - Formula:
=N(D1) - Result:
1(since Excel treatsTRUEas1). - Data in E1:
FALSE - Formula:
=N(E1) - Result:
0(since Excel treatsFALSEas0).
Example 5: Convert an error value to a number
- Data in F1:
#DIV/0! - Formula:
=N(F1) - Result:
0(since errors are not numbers, the function returns0).
Key Points:
- Numbers: If the argument is already a number, N simply returns the same number.
- Dates: Dates in Excel are stored as serial numbers, so N will return the serial number of the date.
- Text: If the value is text, N returns
0because text cannot be converted to a numeric value. - Logical Values: TRUE is treated as
1, and FALSE is treated as0by N. - Errors: If the value is an error (e.g.,
#DIV/0!,#VALUE!), N returns0.
Use Cases:
- Converting Non-Numeric Data: You can use the N function to convert dates, booleans, or text to numeric values for calculations:
=N(A1) + N(B1) ' Add two values and convert them to numbers. - Data Cleaning: N can be helpful when working with data that might contain text or errors, allowing you to perform numeric operations only on valid numbers.
- Summing Logical Values: If you want to treat logical values as numbers for summing or other calculations, use N:
=SUM(N(A1), N(B1), N(C1)) ' Adds numbers and logical values, treating TRUE as 1 and FALSE as 0.