I want to add a comma in the thousands place for a number. String.Format()?
+17
A:
http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
' Format a negative integer or floating-point number in various ways.
Console.WriteLine("Standard Numeric Format Specifiers")
s = String.Format("(C) Currency: . . . . . . . . {0:C}" & vbCrLf & _
"(D) Decimal:. . . . . . . . . {0:D}" & vbCrLf & _
"(E) Scientific: . . . . . . . {1:E}" & vbCrLf & _
"(F) Fixed point:. . . . . . . {1:F}" & vbCrLf & _
"(G) General:. . . . . . . . . {0:G}" & vbCrLf & _
" (default):. . . . . . . . {0} (default = 'G')" & vbCrLf & _
"(N) Number: . . . . . . . . . {0:N}" & vbCrLf & _
"(P) Percent:. . . . . . . . . {1:P}" & vbCrLf & _
"(R) Round-trip: . . . . . . . {1:R}" & vbCrLf & _
"(X) Hexadecimal:. . . . . . . {0:X}" & vbCrLf, _
- 123, - 123.45F)
Console.WriteLine(s)
Adam Driscoll
2008-09-19 21:28:36
+22
A:
String.Format("{0:n}", 1234);
string.Format("{0:n0}", 9876); // no decimals.
Terrapin
2008-09-19 21:29:06
`{0:n}` is giving me unwanted decimal places
Maslow
2010-04-16 00:18:37
{0:n0} will remove those
Hafthor
2010-05-05 17:47:51
A:
string.format("{0:#,###,###.##}", MyNumber)
That will give you commas at the thousand, and millions point.
Stephen Wrighton
2008-09-19 21:29:07
This is true, but it's not guaranteed to give you commas at the thousand point because it respect the user's locale.
Stephen Wrighton
2008-09-19 21:35:13
@Stephen Wrighton, right back at you: that is true, but it's not guaranteed to respect the user's locale because it uses commas as thousands separator. (As an example, in Portugal the comma is instead the decimal separator.)
ANeves
2010-05-19 17:46:51
+1
A:
int num = 98765432;
Console.WriteLine(string.Format("{0:#,#}", num));
p.campbell
2010-05-20 15:36:29
A:
you can use this code in javascript
function GetNumberWithQ(Price) {
var myNumber = Price.toString(); // Price Is Your Namber Your Number
var myResult = "";
for (var i = myNumber.length - 1; i >= 0; i--)
{
myResult = myNumber[i] + myResult;
if ((myNumber.length - i) % 3 == 0 & i > 0)
myResult = "," + myResult;
}
return myResult;
}
ahmad sarkar
2010-07-23 11:38:31
you can use .WithCommas in any imaginary language too, but this is about c#. -1
atamanroman
2010-07-23 11:54:41
A:
if u want culture specific, you might want to try this.
(19950000.0).ToString("N",new CultureInfo("en-US"))
= 19,950,000.00
(19950000.0).ToString("N",new CultureInfo("is-IS"))
= 19.950.000,00
note: some cultures use , to mean decimal rather than . so becareful.
prabir
2010-10-26 09:22:58