Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 显示没有小数点的数字_C# - Fatal编程技术网

C# 显示没有小数点的数字

C# 显示没有小数点的数字,c#,C#,我想在报表中显示一个数字,但我只想显示任何小数点(如果存在),并且我只想显示1个小数点 e、 如果数字是12,那么我想显示12 如果数字是12.1,那么我想显示12.1 如果数字是12.11,那么我想显示12.1,我刚才遇到了一个非常类似的问题,答案是在将数字转换为字符串时使用格式字符串。解决问题的方法是使用自定义数字格式字符串“0.#” 将为您提供以下输出: 十二, 12.1 12.1这将返回一个带一个(可选)小数位的数字 String.Format("{0:0.#}", number) 那

我想在报表中显示一个数字,但我只想显示任何小数点(如果存在),并且我只想显示1个小数点

e、 如果数字是12,那么我想显示12

如果数字是12.1,那么我想显示12.1


如果数字是12.11,那么我想显示12.1,我刚才遇到了一个非常类似的问题,答案是在将数字转换为字符串时使用格式字符串。解决问题的方法是使用自定义数字格式字符串“0.#”

将为您提供以下输出:

十二,

12.1


12.1这将返回一个带一个(可选)小数位的数字

String.Format("{0:0.#}", number)
那怎么办

Math.Round(12.11,1)?


谢谢EsbenP,我真的应该检查我是否修改了我复制和粘贴的部分。我知道这是一个旧的(正确的)答案,但是链接断了,应该删除。
Math.Round(12.11,1)?
double number = 12.11;
numer.ToString("0.00")