Sub topic 11
Turning extracted text into numbers
This chapter assumes you can enter formulas, reference cells and ranges, and use functions such as IFERROR and TRIM. It also assumes you have used REGEXEXTRACT to pull a pattern out of a cell. The goal here is to turn the text that REGEXEXTRACT returns into numbers you can add, compare, and sort.
Why extracted digits are not numbers
REGEXEXTRACT always returns text. This holds even when the matched characters are all digits. If A2 contains Total: 4500 USD, this formula returns the text 4500, not the number 4500:
=REGEXEXTRACT(A2, "\d+")You can see the difference in how Sheets displays the value. Text aligns to the left of the cell by default, and numbers align to the right. If a column of "numbers" hugs the left edge, it is probably text.
The same applies to the pieces SPLIT returns. In many cases Sheets converts a split piece to a number automatically if it looks like one, but you should not rely on this. Treat anything produced by a text function as text until you convert it.
What goes wrong with text digits
Text that looks like a number causes quiet problems:
SUMignores text values in a range, so a total can be too low without any error.- Comparisons can behave unexpectedly. Sorting text sorts character by character, so
"100"comes before"9". - Arithmetic on a single cell, such as
=B2*2, often still works because Sheets coerces text to a number in operators. That makes the problem easy to miss until you use a function that does not coerce.
Checking the type with ISNUMBER and ISTEXT
Before converting, confirm what you have. ISNUMBER returns TRUE for a real number, and ISTEXT returns TRUE for text:
=ISNUMBER(REGEXEXTRACT(A2, "\d+"))This returns FALSE, which confirms the extracted value is text. Use these two functions whenever a column of results behaves oddly.
Converting with VALUE
VALUE converts a text string that looks like a number into a number. Wrap the REGEXEXTRACT call in it:
=VALUE(REGEXEXTRACT(A2, "\d+"))For Total: 4500 USD this returns the number 4500. It can now be summed, averaged, and formatted.
VALUE accepts more than plain digits. It can parse text such as 1,200, $35, or 12% according to the spreadsheet's locale, returning 1200, 35, and 0.12. This is convenient, but it depends on the locale setting, which the pitfalls section covers.
If the text cannot be read as a number, VALUE returns a #VALUE! error. For example, VALUE on the text abc fails.
Other ways to convert
VALUE is the clearest option, but there are others you will see in existing sheets.
| Technique | Example | Notes |
|---|---|---|
| VALUE | `=VALUE(B2)` | Explicit and readable. Preferred. |
| Unary double minus | `=--B2` | Coerces text to a number. Short but cryptic. |
| Multiply by 1 | `=B2*1` | Works the same way. Easy to read, but it hides intent. |
| Add 0 | `=B2+0` | Same effect. |
All of these produce #VALUE! when the text is not numeric. Choose VALUE in shared sheets because the next reader can see what the formula is for.
Extracting numbers that are not plain integers
The pattern \d+ matches only a run of digits. It stops at a decimal point or a thousands separator, so it returns only part of a value such as 12.50 or 1,200.
Decimals
To capture a decimal number, allow an optional fractional part:
=VALUE(REGEXEXTRACT(A2, "\d+\.?\d*"))Read the pattern in pieces:
\d+matches one or more digits.\.?matches an optional literal dot. The backslash is needed because an unescaped.matches any character.\d*matches zero or more digits after the dot.
For Price: 12.50 each this returns 12.5. For Qty: 7 it returns 7.
Negative numbers
Add an optional minus sign in front:
=VALUE(REGEXEXTRACT(A2, "-?\d+\.?\d*"))For Change: -3.75 this returns -3.75. Without the -?, the result would be 3.75, which is wrong in sign and easy to miss.
Thousands separators
If values contain commas, such as Revenue: 1,200,500, you can match digits and commas together and let VALUE parse the commas:
=VALUE(REGEXEXTRACT(A2, "\d[\d,]*"))The class [\d,]* allows any number of digits or commas after the first digit. This returns 1200500 in a locale that uses commas as thousands separators.
Alternatively, remove the commas first with SUBSTITUTE. This avoids relying on the locale:
=VALUE(SUBSTITUTE(REGEXEXTRACT(A2, "\d[\d,]*"), ",", ""))Currency symbols
You can leave the symbol out of the capture. Match only the number, and the symbol stays behind:
=VALUE(REGEXEXTRACT(A2, "\$(\d+\.?\d*)"))Here the parentheses create a capture group, so REGEXEXTRACT returns only the part inside them. For Cost: $35.99 the result is 35.99. The \$ escapes the dollar sign, which otherwise means "end of text" in a regular expression.
Converting several capture groups at once
When a pattern has several capture groups, REGEXEXTRACT returns several values that spill into adjacent cells. Each one is text. Wrap the whole call in VALUE to convert them together:
=VALUE(REGEXEXTRACT(A2, "(\d+)x(\d+)"))For Size: 30x45 this returns 30 in one cell and 45 in the next, both as numbers. You can then calculate with them directly:
=PRODUCT(VALUE(REGEXEXTRACT(A2, "(\d+)x(\d+)")))This returns 1350, the area in this case.
If only some groups are numeric, convert them separately. Wrap just the numeric group, or use INDEX to select a piece:
=VALUE(INDEX(REGEXEXTRACT(A2, "([A-Z]+)-(\d+)"), 1, 2))For ORD-10492, REGEXEXTRACT returns ORD and 10492. INDEX with row 1 and column 2 selects 10492, and VALUE converts it to the number 10492.
Converting a whole column
Fill-down works, but a single formula is easier to maintain. Use ARRAYFORMULA to apply the conversion to every row:
=ARRAYFORMULA(VALUE(REGEXEXTRACT(A2:A10, "\d+")))This produces one number per row of A2:A10. Two cautions apply:
- If any row has no match, REGEXEXTRACT returns
#N/Afor that row, and VALUE passes the error through. The error appears only in that row, but it will break any SUM over the result. - Blank cells in the range also produce
#N/A, because an empty string contains no digits.
Handle both by wrapping the extraction in IFERROR. Decide what the fallback should be, and see the next section for why that choice matters.
Combining conversion with IFERROR
Put IFERROR outside VALUE so it catches both a failed match and a failed conversion:
=ARRAYFORMULA(IFERROR(VALUE(REGEXEXTRACT(A2:A10, "\d+")), ""))The fallback "" leaves failed rows visibly empty. Because the fallback is an empty string, those cells are text, not numbers. SUM and AVERAGE ignore them, which is usually what you want. COUNT also ignores them, so a count of numeric results tells you how many rows matched.
Using 0 as the fallback behaves differently:
=ARRAYFORMULA(IFERROR(VALUE(REGEXEXTRACT(A2:A10, "\d+")), 0))Now unmatched rows count as real zeros. AVERAGE includes them and lowers the result. Pick "" when "no data" must not influence statistics, and pick 0 only when a missing value genuinely means zero.
Worked example
Suppose column A holds free-text order notes, and you want the quantity as a number.
| Row | A (notes) |
|---|---|
| 2 | Qty: 12 units |
| 3 | Qty: 7 |
| 4 | Quantity not given |
| 5 | Qty: 150 units |
Use this formula in B2:
=ARRAYFORMULA(IFERROR(VALUE(REGEXEXTRACT(A2:A5, "\d+")), ""))The results are 12, 7, an empty cell, and 150. Then this formula in D1 sums the quantities:
=SUM(B2:B5)It returns 169. Row 4 contributes nothing, because it is an empty-string result and SUM ignores text.
The diagram shows the path each cell takes through the formula.
Pitfalls and edge cases
Locale decides how VALUE reads separators
In a spreadsheet set to a locale such as German or French, the decimal separator is a comma and the thousands separator is a dot or a space. Then VALUE("12.50") may fail or read the text as something else, and VALUE("1,5") returns 1.5. Check the locale under File, Settings. If your data comes from a different locale than the sheet, normalize the separators with SUBSTITUTE before calling VALUE.
Leading zeros are lost
Converting 00123 with VALUE returns 123. This is correct for quantities and wrong for identifiers such as postal codes or order IDs. If the leading zeros matter, keep the value as text and do not convert it.
Very long digit strings
Sheets stores numbers with about 15 significant digits. A 16-digit card-style or account number loses precision when converted. Keep such values as text.
Spaces and non-breaking spaces
Text copied from web pages may contain non-breaking spaces. A pattern such as \d+ ignores them, but if you feed the whole cell to VALUE, they cause #VALUE!. Extract with a pattern first, as in this chapter, rather than converting the raw cell.
Dates that look like numbers
VALUE on 2026-11-27 returns a date serial number (46,353 or similar), not the digits. If you want the year as a number, extract it with a pattern such as (\d{4}) first and then convert.
Format versus value
Applying a Number format to a text cell does not convert it. The cell still holds text. Only a formula such as VALUE, or the arithmetic coercions above, changes the stored type.
Summary of the approach
- Extract the digits with a pattern that includes any sign, decimal point, or separators you need.
- Convert with VALUE, after removing separators if the locale could interfere.
- Wrap the result in IFERROR with a fallback that suits the calculation.
- Test with ISNUMBER to confirm the type.
Exercise
Cell A2 contains Weight: -2.5 kg. Write a formula that returns the number -2.5, and a formula for A2:A20 that returns numbers for matching rows and an empty string for rows with no number.
Show answer
For one cell: =VALUE(REGEXEXTRACT(A2, "-?\d+\.?\d*")). The -? keeps the sign, \.?\d* keeps the decimal part, and VALUE turns the extracted text into a number. For the whole range: =ARRAYFORMULA(IFERROR(VALUE(REGEXEXTRACT(A2:A20, "-?\d+\.?\d*")), "")). IFERROR catches the #N/A that rows without a number produce, and the empty string keeps those rows out of SUM and AVERAGE.
Exercise
A column holds Total: 1,250 in A2. The sheet's locale uses a dot as the decimal separator and a comma as the thousands separator. Write a formula that returns 1250 without depending on locale parsing of commas, then say what =SUM(B2:B10) does with cells that contain the text "1250" instead of the number.
Show answer
Use =VALUE(SUBSTITUTE(REGEXEXTRACT(A2, "\d[\d,]*"), ",", "")). REGEXEXTRACT returns 1,250, SUBSTITUTE removes the comma to give 1250, and VALUE converts it to the number 1250. SUM ignores text values in a range, so cells holding the text "1250" add nothing to the total, which makes the sum too low with no error shown.