Alex Rivera | Logout

String format for only one decimal place?

Asked 2012-08-27T16:47:12.297
37

I'd like to dispaly only one decimal place. I've tried the following:

string thevalue = "6.33";
thevalue = string.Format("{0:0.#}", thevalue);

result: 6.33. But should be 6.3? Even 0.0 does not work. What am I doing wrong?

Edit
Report

1 Answer

40

Here is another way to format floating point numbers as you need it:

string.Format("{0:F1}",6.33);
answered 2012-08-27T17:29:00.243

Your Answer