开发者

formatting double precision values in C#

Say I have a double variable initialized as

double dValue  = 5.156365

I would like to show this in a textbox as 5.16 i.e only two decimal places.

How should I format?

Is textbox.Text = dValue.ToString("F2", Culture.....) correct? When I tried it did give me the correct result. However, if dValue = 5 then I would like only 开发者_StackOverflow5 to be shown and not 5.00.

How could I achieve this in C#?


A 0 in the string forces that decimal place, while a # lets the number get up to that decimal place.

   dValue.ToString("0.##")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜