Avatar of CipherIS
CipherIS
Flag 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?
C#

Avatar of undefined
Last Comment
CipherIS

8/22/2022 - Mon
p_davis

what do you get? what is the value of s?

you can also try string.Format("{0:C}", rdr["myValue"].ToString());
p_davis

are you just getting 0?
p_davis

String.Format("{0:.##}", rdr["myValue"].ToString());
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
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
kaufmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CipherIS

ASKER
Thanks kaufmed!