C# 双字符串格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9869346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Double string.format
提问by falukky
I have some double values I want to convert to a string with this pattern:
我有一些双值我想转换为具有这种模式的字符串:
0.xx or x.xx
Currently I have try this:
目前我已经尝试过这个:
double.ToString("#.#0");
What should I add in order to see zero in case my number start with zero?
如果我的数字以零开头,我应该添加什么才能看到零?
采纳答案by Carsten
just use
只是使用
myDouble.ToString("0.00")
that should do the trick
这应该够了吧
回答by Guffa
Put a zero in front of the decimal separator:
在小数点分隔符前加一个零:
double.ToString("0.#0");
This will always include the digit, in contrast to #which makes it optional.
这将始终包括数字,与此相反,#它使它成为可选的。
回答by ionden
String.Format("{0:0.00}", 111.0);
回答by Zaki
use following :
使用以下:
myDouble.ToString("N2")
回答by raznagul
myDouble.ToString("N2")
should also work.
也应该工作。
Have a look at
看一下
MSDN: Custom Numeric Format Strings

