String to Int

How to Convert a String to an Integer in Excel

Learn how to convert text to a whole number in Excel with VALUE, double negatives, Paste Special and Text to Columns, plus the common pitfalls.

On this page
  1. Why the numbers are stored as text
  2. Use VALUE
  3. Use a double negative
  4. Multiply or add zero
  5. Convert a whole range
  6. Regional separators
  7. Leading zeros and long numbers
  8. Quick comparison
  9. Doing it in code

Why the numbers are stored as text

Excel stores a value as text when it was pasted from another program, imported from a file, or typed with a leading apostrophe. Text that looks like a number is left-aligned by default and often shows a small green triangle. Functions such as SUM skip text values, so a column of text numbers can add up to the wrong total. Converting them is usually worth the effort.

Use VALUE

VALUE turns text that looks like a number into a number. If cell A1 holds the text 42, this formula returns the number 42:

=VALUE(A1)

If the text isn’t a number, VALUE returns #VALUE!.

Use a double negative

Two minus signs in front of a cell reference also convert text to a number:

=--A1

Each minus sign negates the value, so the pair cancels out, and Excel converts the text to a number along the way. It works, but many people find VALUE easier to read.

Multiply or add zero

Formulas like =A1*1 or =A1+0 also make Excel treat the text as a number. For plain numbers they give the same result as the double negative. Use whichever one is easiest for you to read.

Convert a whole range

You don’t need a formula to convert many cells at once.

To use Paste Special:

  1. Type 1 in an empty cell and copy it.
  2. Select the text cells you want to convert.
  3. Choose Home, then Paste, then Paste Special. Select Multiply and click OK.
  4. Delete the 1 you typed.

To use Text to Columns:

  1. Select the column of text.
  2. On the Data tab, choose Text to Columns.
  3. Click Finish without changing the settings. If the column uses the General format, Excel often converts the text to numbers.

If Excel flags cells with green triangles, select them, click the warning icon that appears, and choose Convert to Number.

Regional separators

VALUE reads numbers according to your computer’s regional settings. A text value like 3,5 means three and a half in some regions and something else in others. NUMBERVALUE, available in Excel 2013 and later, lets you state the separators:

=NUMBERVALUE("1.234,5", ",", ".")

This returns 1234.5, because the comma is the decimal separator and the period groups the thousands.

Leading zeros and long numbers

Converting 00123 gives 123. If the leading zeros matter, such as in ZIP codes or product codes, keep those values as text. Excel also keeps only about 15 significant digits, so long ID numbers can lose their last digits when they’re converted.

Quick comparison

Method How to use it Notes
VALUE =VALUE(A1) Easy to read; returns #VALUE! for non-numbers
Double negative =--A1 Short, but harder to read
Multiply =A1*1 Works for plain numbers
Paste Special Multiply by 1 Overwrites the original cells
Text to Columns Data tab, then Finish Converts a whole column
Convert to Number Warning icon menu Fast for flagged cells

Doing it in code

The same job in a program uses different tools. C++ gives you functions such as std::stoi for this. For the code version, see c convert string to int.

The complete guide to string to int

How to Convert a String to an Int in C++
Read the guide

Keep exploring

Guides from other topics

All topics →

The Latest C++ Standard

C++23 is the most recent C++ standard at the time of writing, with C++26 next. Here is what changed, how versions are named, and how to compile for each.

C++ Standards 3 min read