
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Print number with commas as 1000 separators in C#
Firstly, set the number as string −
string num = "1000000.8765";
Now, work around differently for number before and after the decimal −
string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf("."));
Use the ToString() method to set the format for 1000 separators −
ToString("#,##0")
The following is the complete code to display number with commas as 1000 separators −
Example
using System; public class Program { public static void Main() { string num = "1000000.8765"; string withoutDecimals = num.Substring(0, num.IndexOf(".")); string withDecimals = num.Substring(num.IndexOf(".")); withoutDecimals = Convert.ToInt32(withoutDecimals).ToString("#,##0"); Console.WriteLine(withoutDecimals + withDecimals); } }
Output
1,000,000.8765
- Related Articles
- Print number with commas as 1000 separators in Python
- How to print a number with commas as thousands of separators in JavaScript?
- How to format number with “.” as thousand separators, and “,” as decimal separator?
- Print 0001 to 1000 in Kotlin with padding
- Replace commas with JavaScript Regex?
- How to trim commas with MySQL?
- MongoDB query to convert a string with commas to double
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- Number of pairs with Bitwise OR as Odd number in C++
- Splitting strings based on multiple separators - JavaScript
- Print Bracket Number in C++
- Find:$(i).\ 7.9 \div 1000$$(ii).\ 26.3 \div 1000$$(iii).\ 38.53 \div 1000$$(iv).\ 128.9 \div 1000$$(v).\ 0.5 \div 1000$
- Print a number containing K digits with digital root D in C++
- What are binary literals and digit separators in C# 7.0?
- How to Add Spaces after Commas in Excel?

Advertisements