add a comma

  • Thread starter Thread starter Ryan Moore
  • Start date Start date
R

Ryan Moore

how do I format a databound field in a datagrid to place a comma for a
currency (eg 126,000)

I'm currently using:

DataBinder.Eval(Container.DataItem, "price", "{0:c}"

thanx
 
You can use the ToString() method, and pass the string "N" to it, as in:

decimal d = 100000.25
string s = d.ToString("N"); // returns "100,000.25"

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
The more I learn, the less I know.
 
Ryan Moore said:
how do I format a databound field in a datagrid to place a comma for a
currency (eg 126,000)
I'm currently using:
DataBinder.Eval(Container.DataItem, "price", "{0:c}"

Ryan,
Try setting the CurrentCulture and CurrentUICulture for the current thread
in the Application_BeginRequest event handler.

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Initialize the CurrentCulture and CurrentUICulture with the
' Browser's user language setting.
Try
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages(0))
Catch
' Culture not supported. Use US English.
Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
End Try
' Set the CurrentUICulture to be the same as CurrentCulture
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture
End Sub

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com
 
This one has always been my favorite for currency in a datagrid.

DataReader.GetSqlMoney(2).ToDouble().ToString(
"$#,,##0.00;($#,##0.00);$0.00" );

has dollar signs, commas and does the () around negative values...

bill


DataReader.GetSqlMoney( 2 ).ToDouble().ToString(
"$#,##0.00;($#,##0.00)" ) );
 
Back
Top