Formatting Strings

G

Guadala Harry

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

Scott Mitchell [MVP]

Guadala said:
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
(e-mail address removed)
http://www.4GuysFromRolla.com

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

Guadala Harry

Perfect - thanks!


Scott Mitchell said:
Guadala said:
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
(e-mail address removed)
http://www.4GuysFromRolla.com

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

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,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top