ok I am trying to convert find cost per sq yd. in $$.$$ format. I have all the coding correct except it has more than two decimal places.

Here is my code:

//delcare const
            const int number = 9;

            //declare variable
            double length;
            double width;
            double area;
            double cost;
            double PricePerSqYd;
            double TotalCost;

            Console.Write(" Enter length of the room: ");
            length = Convert.ToInt32(Console.ReadLine());

            Console.Write(" Enter width of the room: ");
            width = Convert.ToInt32(Console.ReadLine());
            Console.Write(" Enter cost of carpet per square yard: ");
            cost = Convert.ToDouble (Console.ReadLine());

            area = length * width;
            PricePerSqYd = area / number;
            TotalCost = PricePerSqYd * cost;

            Console.WriteLine("The total cost to carpet your room is " + TotalCost);


Edited 6 Years Ago by abarlowa: n/a

for number format use ToString("N2") and currency format use ToString("C2").

Console.WriteLine("Your total is " + TotalCost.ToString("N2"));
This question has already been answered. Start a new discussion instead.