I have a variable of double data type.It has only 1 decimal point or no decimal point such as 17.5 and 17.I want to have exact two decimal point for it.Does anyone know?

public void TestDoubleFormat()
      {
         string format = "0.00";

         double d = 12; 
         string s = d.ToString(format);
         d = 12.1; 
         s += ", " + d.ToString(format);
         d = 12.12;
         s += ", " + d.ToString(format);

         lblOutput.Text = s;
      }

Output:

12.00, 12.10, 12.12

I have a variable of bouble data type.It has only 1 decimal point or no decimal point such as 17.5 and 17.I want to have exact two decimal point for it.Does anyone know?

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.