Click here to Skip to main content
15,029,464 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I would like to format a negative number say -12345 to currency.

Code:
String.Format("{0:c}", -12345);

Result:
($12,345.00)

But I need in the following format

$-12,345.00

How do I code this?
Posted

   
C#
using System;
using System.Globalization;
 
public class Test
{
	public static void Main()
	{
	    Decimal dec = new Decimal(-1234.4321);
	    CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
	    culture.NumberFormat.CurrencyNegativePattern = 1; 
	    String str = String.Format(culture, "{0:C}", dec);
	    Console.Write(str);
	}
}

This may help.
   
Comments
ckumaresanmba 12-Feb-14 4:44am
   
For my query, the currencyNegativePattern should be 2. Anyway thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900