.NET货币字符串燮pressing前导零,如果值小于; 1前导、字符串、货币、NET

2023-09-06 18:21:07 作者:枭雄战

我有一个问题。找不到格式,转换成十进制为货币字符串没有前导零如果是小于1。

I have an issue. Cannot find format which converts decimal to currency string without leading zeros if it is less that 1.

例如。

decimal d = 0.14M;
d.ToString("C"); // Translates to   $0.14  But I need to get  $ .14

是否有一些特殊的precision符丰富这样的效果只是调用toString?

Are there some special precision specifiers to rich such an effect just calling ToString ?

推荐答案

试试这个:

string result = String.Format("{0:#.0}", d);

来源: http://www.csharp-examples.net/string-format备有双人床/