Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting a double

Status
Not open for further replies.

kmfna

MIS
Sep 26, 2003
306
US
Hello all,

I have a datagrid that I am binding to a data set and I need to be able to display some of the columns in a currency type format...ie 3 -> 3.00 or 0 -> 0.00 .

Any ideas?? I've been trying to force the column to do this by using

Code:
Convert.ToDouble(valid.ModNum(e.Row[11].ToString())).ToString("##.00")

valid.ModNum is a function that should return a string in the correct format...however I have to convert it to a double to repopulate the dataset, so I use the .ToString("##.00") to force it. This works for some numbers, but 0 always just shows up as 0....I'm getting a little irritated with this, so any ideas would be great!

Thanks in advance!

Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Take a look here and choose or modify the format that you want. On the comments I put the output when the regional settings are set to English (Canada)
Code:
string s1x = string.Format("{0:$#,##0.00;($#,##0.00);Zero}", 1955.671);  // $1,955.67
 string s2x = string.Format("{0:$#,##0.00; ($#,##0.00);Zero}", 1955.67);  // $1,955.67
string s3x = string.Format("{0:$#,##0.00;($#,##0.00);Zero}", 1955.6);  // $1,955.60
string s4x = string.Format("{0:$#,##0.00;($#,##0.00);Zero}", 1955);    // $1,955.00
string s5x = string.Format("{0:$#,##0.00;($#,##0.00);Zero}", 0);       // Zero
or
Code:
string s6x = string.Format("{0:$#,##0.00}", 0); // $0.00
string s7x = string.Format("{0:$#,##0.00;($#,##0.00)}", -1955.892); // ($1,955.89)
I think
string s10 = string.Format("{0:$#,##0.00}", val);
will format as you want. Be aware that the Format uses default CultureInfo.
-obislavu-

 
hmmm...I hadn't tried string.format....but can I place that into a double column of a datagrid or am I going to get a type mismatch error??

Thanks Obi,

Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
you can use it as format property

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
great...thanks guys....I finally got what I was looking for!

Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top