Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

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

I have a value I am retrieving from a database.  I am assigning the value to a text box on my asp.net 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;

and

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

But neither works.

Any ideas?
Avatar of p_davis
p_davis

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());
Avatar of CipherIS

ASKER

@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"
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks kaufmed!