Question Formatting numbers for DataGridView

xsys

New member
Joined
Mar 17, 2010
Messages
4
Programming Experience
5-10
I am trying to format a DataGridView column to show values formatted as follows:

100.222 => 100.22
0 =>
22 => 22.00
3123 => 3,123.00


I can't seem to achieve this with any formatting string. The (#) is great because if the number is 0, it doesn't show, however when trying to force 2 trailing decimal numbers, it doesn't work. The (0) is great as it creates the trailing decimal numbers but if the value is 0, it still shows it.

The closest formatting string for the above is (#,#.00) but produces this:

100.222 => 100.22
0 => .00 (this line is the problem)
22 => 22.00
3123 => 3,123.00


How can I format it in a way to overcome this? Thanks.....
 
I figured out the answer to my question using another article showing string formatting for c#.

The format string to solve this problem is (#,#.00;#,#.00;#)

Their are 3 parts (seperated by a semi-colon ; ). First part is for a standard value, second is for a negative value, third is for Zero values.
 
Last edited:
Back
Top