Alex Rivera | Logout

String.Format("{0:C2}", -1234) (Currency format) treats negative numbers as positive

Asked 2009-06-16T12:18:11.697
21

I am using String.Format("{0:C2}", -1234) to format numbers.

It always formats the amount to a positive number, while I want it to become $ - 1234

Edit
Report

1 Answer

24

Another simple option is manually specify the format string.

String.Format("{0:$#,##0.00}", -1234)

Or, if the currency symbol needs to be a parameter, you could do this

String.Format("{0:" + symbol + "#,##0.00}", -1234)
answered 2011-06-21T15:56:57.067

Your Answer