c# - How to format a string as currency using localization

String format currency localization
string-format-currency-localization.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 an int variable.
        int integerValue = 123;
        
        //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 decimal variable.
        decimal decimalValue = 421.86M;

        //this line create double variable.
        double doubleValue = 741.15;

        Label1.Text = "Integer: " + integerValue;
        Label1.Text += "<br />Decimal: " + decimalValue;
        Label1.Text += "<br />Double: " + doubleValue;

        Label1.Text += "<br /><br />string format currency with localization..............";
        //format string using ToString method.
        Label1.Text += "<br />currency localization with [en-US] culture: " + integerValue.ToString("c", usCulture);
        Label1.Text += "<br />currency localization with [fr-FR] culture: " + integerValue.ToString("c", frCulture);
        Label1.Text += "<br />currency localization with [en-GB] culture: " + integerValue.ToString("c", gbCulture);
        Label1.Text += "<br />currency localization with [da-DK] culture: " + integerValue.ToString("c", dkCulture);

        //format string using string.format method.
        Label1.Text += "<br />integer value [en-US]: " + string.Format(usCulture, "{0:c}", integerValue);
        Label1.Text += "<br />decimal value [fr-FR]: " + string.Format(frCulture, "{0:c}", decimalValue);
        Label1.Text += "<br />double value [en-GB]: " + string.Format(gbCulture, "{0:c}", doubleValue);
    }  
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - string format currency localization</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2 style="color:MidnightBlue; font-style:italic;">  
            c# example - string format currency localization
        </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 localization"  
            OnClick="Button1_Click"
            Height="40"  
            Font-Bold="true"  
            />  
    </div>  
    </form>  
</body>  
</html>
More c# examples