我正在格式化一个 0 的 BigInteger 值,结果得到一个空字符串。这是预期的行为吗?
System.Numerics.BigInteger value = 0;
string xx = value.ToString("#", System.Globalization.CultureInfo.InvariantCulture);
xx 是 string.Empty 在这两条语句之后。如果我将值设置为 10,我将得到“10”。
最佳答案
是的,这是预期的行为。来自 MSDN :
If the value that is being formatted has a digit in the position where the "
#
" symbol appears in the format string, that digit is copied to the result string. Otherwise, nothing is stored in that position in the result string.
强调我的
如果您总是想要至少一位数字,则可以使用 0
作为格式字符串:
string xx = value.ToString("0", System.Globalization.CultureInfo.InvariantCulture);
产量:
0
→“0”
10
→“10”
关于c# - 格式化 BigInteger 导致空为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42723891/