Grid view and format of an int

T

ThisBytes5

I need to turn 40000 in to 40,000 for display.

Is there a way to do this directly in the Gridview and I'm just not
seeing it?

or do I have to use a TemplateField and do my own Formatting?

How would I in C# do the formatting? Is there something in
Int.ToString() that would format it for me?

i've not had any luck with google or the help thus far.

Thanks
Wayne
 
S

S. Justin Gengo

Wayne,

Look at the String.Format function. You'll also want to search for "Standard
Numeric Format String".

What you want will be similar to this (although I do most programming in
VB.NET but this will be similar):

String.Format("This is the amount: {0:N}", MyInt)

Here's an excerpt from the MSDN Library's Standard Numeric Format Strings
entry:

N or n Number The number is converted to a string of the form
"-d,ddd,ddd.ddd...",
where each 'd' indicates a digit (0-9). The
string starts with a minus sign
if the number is negative. Thousand
separators are inserted between
each group of three digits to the left of the
decimal point. The precision
specifier indicates the desired number of
decimal places. If the precision
specifier is omitted, the default numeric
precision given by the
NumberFormatInfo is used.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
W

Wayne

Thank you, this is exactly what I needed. The string.Format("{0:n}") gave me
decimal places.

Now off to the help to further explore "Standard Numeric Format String".


--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein
 
M

Mark Rae

Thank you, this is exactly what I needed. The string.Format("{0:n}") gave
me decimal places.

That's also possible with ToString(), if you need it...

int intTest = 40000;
string strTest = intTest.ToString("#,##0.00");
Now off to the help to further explore "Standard Numeric Format String".

It's extremely powerful...
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top