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;

            //input
            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());

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

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

            Console.ReadLine();

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

Solved

Thanks

Be a part of the DaniWeb community

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