How to Convert a Number to a String with ToString in C#
A number and the text that shows it are different things in C#: 3 is an int, and "3" is a string. Where text is needed, such as a JSON value, a label or a file, ToString() turns the number into its text. For numbers with decimals, which text you get depends on the culture.
Syntax
string <text> = <number>.ToString();
string <text> = <number>.ToString(CultureInfo.InvariantCulture);
| Part | What it does |
|---|---|
<number>.ToString() | The number as text, written the way the current culture writes numbers |
ToString(CultureInfo.InvariantCulture) | The number as text in a fixed, culture-independent form, with a . before the decimals. Needs using System.Globalization; |
Microsoft's Int32.ToString reference: "Converts the numeric value of this instance to its equivalent string representation." For an int, it returns "The string representation of the value of this instance, consisting of a negative sign if the value is negative, and a sequence of digits ranging from 0 to 9 with no leading zeroes."
The Example
The program turns a vote count and a negative number into text, then a price with decimals: first in this machine's culture, then in German, then in the invariant culture.
Prerequisites
- The .NET 10 SDK or newer, which runs a single
.csfile withdotnet run. This guide uses .NET SDK 10.0.404.
Step 1: Write the Code
Create a file named main.cs in an empty folder:

using System.Globalization;
int votes = 3;
string text = votes.ToString();
Console.WriteLine(text + " votes");
Console.WriteLine((-42).ToString());
double price = 2.5;
Console.WriteLine(price.ToString());
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
Console.WriteLine(price.ToString());
Console.WriteLine(price.ToString(CultureInfo.InvariantCulture));
CultureInfo.CurrentCulture = ... switches this program to German number formats, the way a German computer would be set up.
Step 2: Run It
dotnet run main.cs
3 votes
-42
2.5
2,5
2.5

votes.ToString()gave"3", which+joined with" votes".-42kept its minus sign.- The price printed as
2.5in this machine's culture, then as2,5in German, which writes a comma before the decimals. - With
CultureInfo.InvariantCulture, it was2.5again, whatever the current culture.
The command is the same in zsh, bash and PowerShell.
A Number Isn't a String
C# doesn't turn a number into text by itself when you assign it:
int votes = 3;
string text = votes;
/Users/you/demo/main.cs(2,15): error CS0029: Cannot implicitly convert type 'int' to 'string'
The build failed. Fix the build errors and run again.
Call ToString(): string text = votes.ToString();.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
string text = votes; | error CS0029: Cannot implicitly convert type 'int' to 'string' | votes.ToString() |
Writing decimals with ToString() for another program to read | On a computer set to German, 2.5 comes out as 2,5 | ToString(CultureInfo.InvariantCulture) |
Forgetting using System.Globalization; | error CS0103: The name 'CultureInfo' does not exist in the current context | Add the using line at the top |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A comma where you expected a decimal point | The current culture writes decimals with a comma | Pass CultureInfo.InvariantCulture |
CS0029 ... 'int' to 'string' | A number assigned to a string | Call ToString() |
FAQ
Do I need ToString when I join a number to text?
No. With + and a string on one side, C# converts the number for you: "Votes: " + votes printed Votes: 3. String interpolation does the same, and uses the current culture too: under German, $"Price: {price}" printed Price: 2,5.
Does the culture change whole numbers too?
For these, no: under German, 3.ToString() and (-42).ToString() still printed 3 and -42. Cultures differ mostly in decimals, and in the separators that formats such as "N0" add.
Conclusion
number.ToString() turns a number into text in the current culture's style, and ToString(CultureInfo.InvariantCulture) into the same text everywhere, which is what other programs expect. Assigning a number straight to a string is error CS0029.
Additional Resources
- Int32.ToString method, on Microsoft Learn.
- CultureInfo.InvariantCulture property, on Microsoft Learn.
