c# - How to format a string as negative currency

String format currency negative
string-format-currency-negative.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>
<%@ Import Namespace="System.Globalization" %>  

<!DOCTYPE html>  
<script runat="server"> 
    protected void Button1_Click(object sender, System.EventArgs e)  
    {
        //this line create a culture for english in us
        CultureInfo usCulture = new CultureInfo("en-US");

        CultureInfo frCulture = new CultureInfo("fr-FR");
        CultureInfo gbCulture = new CultureInfo("en-GB");
        CultureInfo dkCulture = new CultureInfo("da-DK");
        
        //this line create a decimal variable.
        decimal decimalValue = -236666.86M;

        Label1.Text = "negetive decimal value: " + decimalValue;

        Label1.Text += "<br /><br />string format currency negative sign ..............";

        //format string using ToString method.
        Label1.Text += "<br />negetive currency: " + decimalValue.ToString("C");

        //format string using string.format method.
        Label1.Text += "<br /><br />currency negative sign in [en-US] culture: " + string.Format(usCulture, "{0:C}", decimalValue);
        Label1.Text += "<br />currency negative sign in [fr-FR] culture: " + string.Format(frCulture, "{0:C}", decimalValue);
        Label1.Text += "<br />currency negative sign in [en-GB] culture: " + string.Format(gbCulture, "{0:C}", decimalValue);
        Label1.Text += "<br />currency negative sign in da-DK] culture: " + string.Format(dkCulture, "{0:C}", decimalValue);
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - string format currency negative</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:MidnightBlue; font-style:italic;">  
            c# example - string format currency negative
        </h2>  
        <hr width="550" align="left" color="Gainsboro" />  
        <asp:Label   
            ID="Label1"   
            runat="server"  
            Font-Size="Large"  
            >  
        </asp:Label>  
        <br /><br />
        <asp:Button   
            ID="Button1"   
            runat="server"   
            Text="string format currency negative"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# examples