문제

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

소수점이있는 경우 동일한 코드가 소수점 이하 자리를 출력합니다.

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의 표준 숫자 형식 문자열

간단한 문자열. 형식 옵션 :

int a = 10000000;
String.Format("{0:n0}", a); //10,000,000

A.ToString ( "00,000,000")

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top