I want to add a comma in the thousands place for a number.
Would String.Format()
be the correct path to take? What format would I use?
We can use the FORMAT() function to format numbers with commas. When we use this function, we pass the number and a format string. The format string determines how the number will be formatted when returned. The FORMAT() function returns a formatted string representation of the number, based on the values we provide.
The most common way how we format strings is by using string. Format() . In C#, the string Format method is used to insert the value of the variable or an object or expression into another string.
String.Format("{0:n}", 1234); // Output: 1,234.00 String.Format("{0:n0}", 9876); // No digits after the decimal point. Output: 9,876
I found this to be the simplest way:
myInteger.ToString("N0")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With