IT/etc

[C#]string.format 화폐단위 + 소수점

까군 2013. 11. 15. 09:53

int won = 123456890;
Console.WriteLine(string.Format("{0:n0}", won));
Console.WriteLine(string.Format("{0}", won.ToString("n0"))); ;
Console.WriteLine(string.Format("{0:#,##0}", won));
Console.WriteLine(string.Format("{0}", won.ToString("#,##0")));

//결과
//123,456,890
//123,456,890
//123,456,890
//123,456,890

* 소수점 살리기
value = "1234.567";

string.Format("{0:#,##0.###}",Double.parse(value));

 //결과

//소수점 3자리까지...
//1,234.567
// "0"은 0으로...