Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.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# DataGridView上的格式化数字不是我需要的_C#_Winforms - Fatal编程技术网

C# DataGridView上的格式化数字不是我需要的

C# DataGridView上的格式化数字不是我需要的,c#,winforms,C#,Winforms,我的C#WinForm DataGridView中有一个保存数字的视图 问题在于: 0.5 --> shows --> .5 and -45 --> shows --> 45- 在我的DataGridView中,右边的toleft=yes(我必须有这个) 如何修复它?请参阅格式类型和自定义数字格式字符串& &如何格式化DataGridView中的数据-使用DataGridViewCellStyle的属性。 例如(假设您的第一个列的名称为“Value”

我的C#WinForm DataGridView中有一个保存数字的视图

问题在于:

0.5  -->  shows -->  .5     and

-45 -->  shows -->  45-
在我的DataGridView中,右边的toleft=yes(我必须有这个)


如何修复它?

请参阅
格式类型和自定义数字格式字符串
&

&
如何格式化DataGridView中的数据-

使用DataGridViewCellStyle的属性。
例如(假设您的第一个列的名称为“Value”)

Format属性接受字符串“formats”,这在MSDN的这些文章中有很好的解释


双值=.5

var display=value.ToString(“0.00”,System.Globalization.CultureInfo.InvariantCulture))

谢谢你的帮助,好了,现在我看到了0.5,但在我的DataGridView中仍然看到了56-而不是-56-右边的toleft=yes(我必须有这个)@Gali抱歉,但我在这里真的帮不上忙。右边到左边会改变数字的显示,我认为你应该像前面讨论的那样处理CellPaint事件。你看过我之前评论中的链接了吗?有一个此事件处理的示例
dataGridView1.Columns["Value"].DefaultCellStyle.Format = "0.0";