Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
400 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...