2014-01-14 6 views
1

저는 콘솔 응용 프로그램으로 사람 등록을 만들고 문자열에 전달하려고하는 여러 가지 데이터 형식을 사용하고 있습니다.문자열 형식, 소수점을 표시 할 수 없습니다.

모든 것이 10 진수로 올바르게 변환 된 것처럼 보입니다. "평균 소득"소수 생성자 밖으로 개체를 만들 때 쓰는 숫자가 표시되지 않습니다. 왜 이런 일이 일어나고 이것에 대한 쉬운 해결책이 있습니까? 나는 어떤 방법으로 값을 변환해야 같은데요

..

public class PersonRegistry : IPersonRegistry 
{ 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    public int YearOfBirth { get; set; } 

    public string Country { get; set; } 
    public string City { get; set; } 
    public string State { get; set; } 
    public int Zip { get; set; } 

    public string Occupation { get; set; } 
    public decimal AvarageIncome { get; set; } 

    public PersonRegistry(string Fname, string Lname, int year, string country, string city, 
          string state, int zip, string occupation, decimal income) 
    { 
     FirstName = Fname; 
     LastName = Lname; 
     YearOfBirth = year; 

     Country = country; 
     City = city; 
     State = state; 
     Zip = zip; 

     Occupation= occupation; 
     AvarageIncome = income; 
    } 

    public override string ToString() 
    { 
     return string.Format("* First name: {0}\n* Last name: {1}\n* Born: {2}\n* Country: {3}\n* State: {4}\n* Oklahoma: {5}\n* Zip code: {6}\n* Occupation: {7:C}\n* Income: ", 
           FirstName, LastName, YearOfBirth, Country, City, State, Zip, Occupation, AvarageIncome); 
    } 
} 

static void Main(string[] args) 
{ 
    PersonRegistry p1 = new PersonRegistry("Chuck", "Norris", 1940, "United States", "Ryan", "Oklahoma", 73565, "Actor", 1921.39m); 
    PersonRegistry p2 = new PersonRegistry("Arnold", "Schwarzenegger", 1947, "Austria", "Thal", "Steiermark", 8113, "Actor, politician, bodybuilder", 3.289654m); 

    var PersonRegList = new List<PersonRegistry>(); 
    PersonRegList.Add(p1); 
    PersonRegList.Add(p2); 

    foreach (var person in PersonRegList) 
    { 
     Console.WriteLine(person); 
     Console.ReadLine(); 
    } 
} 
+1

포맷은 확실히 문제 ... –

+4

이다 "... 소득 : {8} "아마도? – Plue

+0

LOL은 당황했고, 8을 잊어 버렸습니다. 죄송합니다. – koffe14

답변

0

이 있어야한다 :

return string.Format("* First name: {0}\n* Last name: {1}\n* Born: {2}\n* Country: {3}\n* State: {4}\n* Oklahoma: {5}\n* Zip code: {6}\n* Occupation: {7:C}\n* Income:{8} ", 
          FirstName, LastName, YearOfBirth, Country, City, State, Zip, Occupation, AvarageIncome); 
관련 문제