I want to format monetary values in my DataGrid so that they start with the dollar sign ($).
How can I do this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you’re talking about showing the data in a monetary format, or even simply adding a “$” to the beginning of data so that
1.49
displays as
$1.49
then you can do this in several ways. On a DataGrid control (web) you can set the DataFormatString property.
One option is to set it to “c” for Currency on a BoundColumn. This will work if your web server’s CultureInfo is set to en-US
Another option is to use a CustomFormatString, which gives you more refined control over how it’s displayed. Say you always want it to be EXACTLY three digits to the right of the decimal and EXACTLY two digits to the left, you can use
{0:$00.000}
More information on custom data format strings for numbers can be found here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
Since you’re working in WinForms, (sorry, I just re-read the comments) you would use the same technique but apply it to the column’s DefaultCellStyle as shown here: http://msdn.microsoft.com/en-us/library/f9x2790s.aspx