Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using BoundField.DataFormatString to format currency data, no $'s and negative numbers should be in ( )'s

I have a gridview that I am populating with data for the folks in accounting and they want me to format currency values so that they display without $'s, with commas separating digits and with negative numbers surrounded by ( )

e.g.:

 12345.67 = 12,345.67
-12345.67 = (12,345.67)

I have found lots of examples around the interwebs that get me close but there is either no ( ) around negatives or there is a $ included.

like image 891
kaelle Avatar asked Dec 01 '25 01:12

kaelle


1 Answers

So I guess basically the question was, what is the String.Format() call that I would make to format a currency value to the aforementioned requirements.

After messing around with some custom formats I figured it out!

var amt = new BoundField ();
amt.DataFormatString = "{0:#,##0.00;(#,##0.00);0}";

Works like a charm.

like image 75
kaelle Avatar answered Dec 02 '25 14:12

kaelle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!