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);


Recommended Answers

All 3 Replies

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

Console.WriteLine("Your total is " + TotalCost.ToString("N2"));
Console.WriteLine("Your total is " + TotalCost.ToString("####0.00");



Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.