먼저 숫자를 문자열로 설정하십시오 -
string num = "1000000.8765";
이제 소수점 앞과 뒤의 숫자에 대해 다르게 해결하십시오 -
string withoutDecimals = num.Substring(0, num.IndexOf("."));
string withDecimals = num.Substring(num.IndexOf(".")); ToString() 메서드를 사용하여 1000개의 구분 기호 형식을 설정합니다. -
ToString("#,##0") 다음은 1000개의 구분 기호로 쉼표를 사용하여 숫자를 표시하는 완전한 코드입니다. -
예시
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);
}
} 출력
1,000,000.8765