String format for only one decimal place?

.net, c#

Solution

You need it to be a floating-point value for that to work.

double thevalue = 6.33;

Here's a demo. Right now, it's just a string, so it'll be inserted as-is. If you need to parse it, use `double.Parse` or `double.TryParse`. (Or `float`, or `decimal`.)

Problem

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?

Original source

Related problems