It depends on the value of your CurrentCulture.NumberFormat.CurrencyNegativePattern . Possible values: from 0 to 15:
0 : ($12,345.00) 1 : -$12,345.00 2 : $-12,345.00 3 : $12,345.00- 4 : (12,345.00$) 5 : -12,345.00$ 6 : 12,345.00-$ 7 : 12,345.00$- 8 : -12,345.00 $ 9 : -$ 12,345.00 10 : 12,345.00 $- 11 : $ 12,345.00- 12 : $ -12,345.00 13 : 12,345.00- $ 14 : ($ 12,345.00) 15 : (12,345.00 $)
So it looks like you want to set it to 1 to get the result you are using, with something like:
int value = -12345; var numberFormat = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); numberFormat.CurrencyNegativePattern = 1; string numberAsCurrency = value.ToString("C", numberFormat)
Although, based on your comments that this is a remote server, and you always want to format it in a certain way, it might be better to just set the culture for the entire stream to a controlled value, and this will affect all subsequent ToString() calls this stream:
int value = -12345; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US"); Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyNegativePattern = 1; string numberAsCurrency = value.ToString("C");
Martin harris
source share