469,621 Members | 1,733 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Formatting Strings

So far into my forray into .NET I have not had to format strings... until
now. I have a stored procedure that returns a decimal value that looks like
this: 12345.1234.

I would like to format it to look like this: $12,345.12

The formatted value should be rounded to two decimal places.

The value to be formatted currently shows up in my code in a DataRow like
this: Convert.ToString(DR_Items["Price"])

Thanks.
Nov 18 '05 #1
2 1011
Guadala Harry wrote:
So far into my forray into .NET I have not had to format strings... until
now. I have a stored procedure that returns a decimal value that looks like
this: 12345.1234.

I would like to format it to look like this: $12,345.12

The formatted value should be rounded to two decimal places.

The value to be formatted currently shows up in my code in a DataRow like
this: Convert.ToString(DR_Items["Price"])


Look into String.Format(). There are a number of format specifiers that
you can use that do specific formatting. You'd likely want the currency
formatting here:

string formattedResults = string.Format("{0:c}", DR_Items["Price"]);

hth

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #2
Perfect - thanks!
"Scott Mitchell [MVP]" <mi******@4guysfromrolla.com> wrote in message
news:%4*****************@newssvr13.news.prodigy.co m...
Guadala Harry wrote:
So far into my forray into .NET I have not had to format strings... until now. I have a stored procedure that returns a decimal value that looks like this: 12345.1234.

I would like to format it to look like this: $12,345.12

The formatted value should be rounded to two decimal places.

The value to be formatted currently shows up in my code in a DataRow like this: Convert.ToString(DR_Items["Price"])


Look into String.Format(). There are a number of format specifiers that
you can use that do specific formatting. You'd likely want the currency
formatting here:

string formattedResults = string.Format("{0:c}", DR_Items["Price"]);

hth

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Steve Holden | last post: by
7 posts views Thread by BBFrost | last post: by
4 posts views Thread by Robert Manookian | last post: by
2 posts views Thread by David Veeneman | last post: by
4 posts views Thread by Peter Newman | last post: by
11 posts views Thread by Dustan | last post: by
9 posts views Thread by john coltrane | last post: by
6 posts views Thread by Tomasz J | last post: by
2 posts views Thread by Jean-Paul Calderone | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.