Input string was not in a correct format .NET Origin: Application & API Last updated 14 Oct 2026

System.FormatException: Input string was not in a correct format

int.Parse/decimal.Parse/Convert.ToInt32 got a string that isn’t a valid number — empty, contains text, or uses another culture’s decimal separator.

Exact message you may see Input string was not in a correct formatThe input string 'abc' was not in a correct format
Seen on: .NET

Meaning

“1,5” fails under en-US, “1.5” fails under de-DE. Empty strings and whitespace also throw. Use TryParse and an explicit CultureInfo.

Common causes

  • Empty or non-numeric string
  • Culture-specific decimal/thousand separators
  • Currency symbols or spaces
  • Parsing user input without validation

⚡ Quick fix

  1. Use int.TryParse / decimal.TryParse
  2. Pass CultureInfo.InvariantCulture for machine data
  3. Trim and validate input

Detailed fix by platform

C#

  1. csharp
    if (!decimal.TryParse(text, NumberStyles.Number, CultureInfo.InvariantCulture, out var amount))
        return BadRequest("Invalid amount");

How to diagnose

  1. Value — Exact string
  2. Culture — CurrentCulture on server

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

DateTimeParseException — java.time.format.DateTimeParseException: Text '31/12/2024' could not be parsed at index 2 (Java)DateTimeParseExceptionInputMismatchException — java.util.InputMismatchException (Scanner) (Java)InputMismatchExceptioninvalid time value — RangeError: Invalid time value (JavaScript)invalid time valueNumberFormatException — java.lang.NumberFormatException: For input string: "x" (Java)NumberFormatExceptionUnable to cast object of type — System.InvalidCastException: Unable to cast object of type 'X' to type 'Y' (.NET)Unable to cast object…Unparseable date — java.text.ParseException: Unparseable date: "x" (Java)Unparseable dateValueError — ValueError: invalid literal for int() with base 10: 'abc' (Python)ValueErrorInput str…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.