كيف يمكنني تنسيق رقم بفواصل؟
سؤال
int a = 10000000;
a.ToString();
وكيف يمكنني جعل الإخراج؟
<اقتباس فقرة>10،000،000
اقتباس فقرة>المحلول
وحاول N0
عن أي جزء عشري:
string formatted = a.ToString("N0"); // 10,000,000
نصائح أخرى
ويمكنك أيضا القيام String.Format:
int x = 100000;
string y = string.Empty;
y = string.Format("{0:#,##0.##}", x);
//Will output: 100,000
إذا كان لديك عشري، نفس رمز سيتم إخراج 2 عشرية:
double x = 100000.2333;
string y = string.Empty;
y = string.Format("{0:#,##0.##}", x);
//Will output: 100,000.23
لجعل فاصلة بدلا من استخدام عشري هذا:
double x = 100000.2333;
string y = string.Empty;
y = string.Format(System.Globalization.CultureInfo.GetCultureInfo("de-DE"), "{0:#,##0.##}", x);
وa.ToString("N0")
وانظر أيضا: ستاندرد الرقمية تنسيق سلاسل من MSDN
وثمة خيار String.Format بساطة:
int a = 10000000;
String.Format("{0:n0}", a); //10,000,000
وa.tostring ( "00000000")
لا تنتمي إلى StackOverflow