add a comma

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
 
K

Kevin Spencer

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.
 
C

Carl Prothman [MVP]

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
 
W

William F. Robertson, Jr.

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)" ) );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top