ASP.NET - C# - Format string to numeric value

CipherIS used Ask the Experts™
I have a value I am retrieving from a database.  I am assigning the value to a text box on my form.  The field in the database is a money value.  I want the below result.

Database Value     Result Value
0.000000                0.00

I have tried the following

string s = string.Format("{0:c}", rdr["myValue"].ToString());
this.myTextBox.text = s;


string s = string.Format("{0:#,0.00}", rdr["myValue"].ToString());
this.myTextBox.text = s;

But neither works.

Any ideas?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
what do you get? what is the value of s?

you can also try string.Format("{0:C}", rdr["myValue"].ToString());
are you just getting 0?
String.Format("{0:.##}", rdr["myValue"].ToString());
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.


@p_davis - I'm getting "0.0000" as a result for
string s = string.Format("{0:c}", rdr["myValue"].ToString());

I tried string s = string.Format("{0:C}", rdr["myValue"].ToString());
and still getting "0.0000"
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
You cannot call ToString and use a numeric format at the same time. Cast the thing returned from the database to a numeric type; then apply the format.


string s = string.Format("{0:c}", (double)rdr["myValue"]);

Open in new window


Thanks kaufmed!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial