Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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
.net 在大于999的数字中插入_.net_Vb.net - Fatal编程技术网

.net 在大于999的数字中插入

.net 在大于999的数字中插入,.net,vb.net,.net,Vb.net,我正在做一个项目,计算给定国家的总人口及其数十万。我需要在适当的地方输出人口和 例:人口123456789 我需要将其输出到列表框中作为 123456789 所以我在寻找一个转换函数或内置的东西,采取我的价值 作为int的模糊总体 并适当地添加它 Lbxdata.Items.Add("----------------------------") Lbxdata.Items.Add(("Total Countries Selected " & countrycount))

我正在做一个项目,计算给定国家的总人口及其数十万。我需要在适当的地方输出人口和 例:人口123456789 我需要将其输出到列表框中作为 123456789

所以我在寻找一个转换函数或内置的东西,采取我的价值 作为int的模糊总体

并适当地添加它

    Lbxdata.Items.Add("----------------------------")

    Lbxdata.Items.Add(("Total Countries Selected " & countrycount))

    Lbxdata.Items.Add(("Total Population Selected " & (totalPopulation))

    Lbxdata.Items.Add("----------------------------")

是我的自动取款机。

您应该将您的号码格式化为

value.ToString("0,0", CultureInfo.InvariantCulture)
因此,您的代码可以是:

Lbxdata.Items.Add("Total Countries Selected " & _
    countrycount.ToString("0,0", CultureInfo.InvariantCulture))
Lbxdata.Items.Add("Total Population Selected " & _
    totalPopulation.ToString("0,0", CultureInfo.InvariantCulture))

请参见文档

您可以将整数转换为字符串或字符数组,只需从Strin.lenght()-1向后每隔三位插入一个逗号,然后使用此字符串设置视图的文本属性

或者转换为string并使用string.Format(“#####,###”)

用于设置行的格式:

Lbxdata.Items.Add(String.Format("Total Countries Selected {0:N0}", countrycount))

Lbxdata.Items.Add(String.Format("Total Population Selected {0:N0}", totalPopulation))

我首先将整数转换为字符串,然后在适当的位置插入逗号<例如,code>mid(string,4,7)可以从string@yosukesabai在.net中,这不是推荐的解决方案。@CodeInChaos:我想在“vb”中,这也是一个糟糕的答案。我读了标题,写了答案,没有想太多,解释得太字面了。。。或者除了可以使用格式化方法之外还有什么特别的原因吗?我只讨论了.net,因为我不知道VB6中可以使用哪些格式化方法。我认为这是不使用不变区域性的一个例子。123031是什么意思?这取决于你生活在大西洋的哪一边。不考虑这一点是错误的