格式化数字以在大于千时显示逗号 [英] Format a number to display a comma when larger than a thousand
问题描述
我正在Visual Basic.net中编写一些代码,并且有一个问题.
I am writing some code in Visual Basic.net and have a question.
如果我有一个大于1000的长整数,如何将该值格式化为1000(带逗号)并将其存储在字符串中?
If I have a long number, that is larger than 1000, how can I format this value to be 1,000 (with a comma) and for this to be stored in a string?
例如
1234将存储为1,234 12345将被存储为12,345 123456将被存储为123,456
1234 will be stored as 1,234 12345 will be stored as 12,345 123456 will be stored as 123,456
这是通过TryParse语句完成的吗?
Is this done with a TryParse statement?
我可以帮些忙吗?
推荐答案
看看一般用途:
Dim dblValue As Double = -12445.6789
Console.WriteLine(dblValue.ToString("N", CultureInfo.InvariantCulture))
' Displays -12,445.68
如果仅使用整数,则执行以下操作:
If you are only using integers then the following:
Dim numberString As String = 1234.ToString("N0")
将显示numberString = "1,234"
,因为"N0"
格式不会在小数点后添加任何数字.
Will show numberString = "1,234"
as the "N0"
format will not add any figures after a decimal point.
这篇关于格式化数字以在大于千时显示逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!