String.Format way to format Currency without Cents

Specify you want zero decimal places:

String.Format("{0:C0}", item.DonationAmount)

Other Way

decimal value = 0.00M;
        value = Convert.ToDecimal(12345.12345);
        Console.WriteLine(".ToString(\"C\") Formates With Currency $ Sign");
        Console.WriteLine(value.ToString("C"));
        //OutPut : $12345.12
        Console.WriteLine(value.ToString("C1"));
        //OutPut : $12345.1
        Console.WriteLine(value.ToString("C2"));
        //OutPut : $12345.12
        Console.WriteLine(value.ToString("C3"));
        //OutPut : $12345.123
        Console.WriteLine(value.ToString("C4"));
        //OutPut : $12345.1235
        Console.WriteLine(value.ToString("C5"));
        //OutPut : $12345.12345
        Console.WriteLine(value.ToString("C6"));
        //OutPut : $12345.123450
        Console.WriteLine();
        Console.WriteLine(".ToString(\"F\") Formates With out Currency Sign");
        Console.WriteLine(value.ToString("F"));
        //OutPut : 12345.12
        Console.WriteLine(value.ToString("F1"));
        //OutPut : 12345.1
        Console.WriteLine(value.ToString("F2"));
        //OutPut : 12345.12
        Console.WriteLine(value.ToString("F3"));
        //OutPut : 12345.123
        Console.WriteLine(value.ToString("F4"));
        //OutPut : 12345.1235
        Console.WriteLine(value.ToString("F5"));
        //OutPut : 12345.12345
        Console.WriteLine(value.ToString("F6"));
        //OutPut : 12345.123450

        Console.WriteLine();
        Console.WriteLine(".ToString(\"N\") Formates With out Currency Sign");
        Console.WriteLine(value.ToString("N"));
        //OutPut : 12,345.12
        Console.WriteLine(value.ToString("N1"));
        //OutPut : 12,345.1
        Console.WriteLine(value.ToString("N2"));
        //OutPut : 12,345.12
        Console.WriteLine(value.ToString("N3"));
        //OutPut : 12,345.123
        Console.WriteLine(value.ToString("N4"));
        //OutPut : 12,345.1235
        Console.WriteLine(value.ToString("N5"));
        //OutPut : 12,345.12345
        Console.WriteLine(value.ToString("N6"));
        //OutPut : 12,345.123450

        Console.WriteLine();
        Console.WriteLine(".ToString(\"P\") Formates With Percentage (i.e multiply by 100)");
        Console.WriteLine(value.ToString("P"));
        //OutPut : 1,2345,12.35%
        Console.WriteLine(value.ToString("P1"));
        //OutPut : 1,2345,12.3%
        Console.WriteLine(value.ToString("P2"));
        //OutPut : 12345,12.35%
        Console.WriteLine(value.ToString("P3"));
        //OutPut : 12345,12.345%
        Console.WriteLine(value.ToString("P4"));
        //OutPut : 12345,12.3450%
        Console.WriteLine(value.ToString("P5"));
        //OutPut : 12345,12.34500%
        Console.WriteLine(value.ToString("P6"));
        //OutPut : 12345,12.345000%


        Console.Read();

 

Spread the love

Similar Posts