c# - 如何将 0 小数解析为字符串?

标签 c# string decimal

为什么当我解析小数点 (0) ToString 时,我的字符串在使用该方法时显示为空:

String somthing = someDecimal.ToString("#")

当我使用时:

String somthing = somDecimal.ToString("0.##")

字符串显示为 0?

当我在 Debug模式下以两种方式查看值时,它说它们中有一个“0”。

最佳答案

来自 The "#" Custom Specifier

Note that this specifier never displays a zero that is not a significant digit, even if zero is the only digit in the string. It will display zero only if it is a significant digit in the number that is being displayed.

如果要显示小数点后的数字,需要使用0.00而不是0.##

关于c# - 如何将 0 小数解析为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22981660/

相关文章:

c# - .Net Core Azure认知搜索删除文档

c++ - 字符串中的数字总和(使用字符串对象)C++

c - 为什么我的链接列表有错误的数据?

Android numberDecimal,考虑 xml 布局中的语言环境

decimal - 解构神奇宝贝故障?

python - 19 位长整数的截断问题

c# - 正则表达式从 HTML 内容中获取 href 和 src?

c# - DataGridCell 的行索引

c# - 如何返回满足条件 C# 的 ObservableCollection 中的所有项目

c - 使用循环在 c 中反转字符串....