c# - 有符号数 + 或 -

标签 c# string-formatting sign

<分区>

Possible Duplicate:
How to force a sign when formatting an Int in c#
Format number with + and - sign

我想在有正数或负数时签名(c#):

text = cname + " " + String.Format("{0:0.#}", move) + "%  , \n " + text;

我想要正数的格式,如“+2.5%”。 有什么想法吗?

最佳答案

查看 MSDN:Format Number To Display

string MyString = number.ToString("+#;-#;0"); 

; - 节分隔符 - 为正数、负数和零数 定义带有单独格式字符串的节。

关于c# - 有符号数 + 或 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10811387/

相关文章:

c# - Visual Studio/C# 自动格式化。我可以控制属性后的换行符吗

c# - .NET Math.Log10() 在不同机器上的行为不同

python - 理解字符串格式中的 Python %g,实现 Java String.format 行为

regex - python : extract all placeholders from format string

c# - 格式错误的引用元素签署账单的 xml 文件

node.js - 在 Node.js 加密中使用 sign.sign() 时出错,解密错误

php - 在 PHP 中更改数字的符号?

c# - 在 Scatterview 中删除已在 C# LibraryStack 中使用的文件

c# - Metro - 编写异步 c# 操作并从 javascript 调用

python - 将两个列表之间的数据排序到一个新列表中,并使用新列表中保存的数据格式化字符串列表