c# - How to format a string as currency without decimal

String format currency no decimal
the following asp.net c# example code demonstrate us how can we format a string (containing numeric value) to currency with no decimal digit programmatically at run time in an asp.net application. In this example, we format a string object containing a decimal number to its equivalent number by rounding it a nearest integer value with dollar currency sign.

A decimal number is a floating-point value that consists of a sign. .Net framework's Decimal.ToString() method convert the numeric value of this instance to its equivalent string representation. Here we also format the decimal digit using ToString() method.

ToString("C") method format specifier "C" or "c" name is currency. This format specifier return a currency value. We can also use a precision specifier to specify number of decimal digit such as ToString("C2"). This ToString("C2") method format a numeric value to its equivalent string representation with currency sign and two decimal digits. So, if we set the method as ToString("C0") then the method format the numeric value with currency sign and without any decimal digit. It round the decimal number to its nearest integer equivalent.

<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>  
<script runat="server"> 
    protected void Button1_Click(object sender, System.EventArgs e)  
        //this line create an int variable.
        int number = 123;

        //this section create decimal variables.
        decimal decimalValue = 421.86M;
        decimal decimalValue2 = 2222.222M;

        //this section create double variables.
        double doubleValue = 741.15;
        double doubleValue2 = 235.47777;
        double doubleValue3 = 235.9;

        Label1.Text = "Integer: " + number;
        Label1.Text += "<br />Decimal: " + decimalValue;
        Label1.Text += "<br />Decimal2: " + decimalValue2;
        Label1.Text += "<br />Double: " + doubleValue;
        Label1.Text += "<br />Double2: " + doubleValue2;
        Label1.Text += "<br />Double3: " + doubleValue3;

        Label1.Text += "<br /><br />formatted string..............";
        //format string using ToString method.
        Label1.Text += "<br />format number to currency no decimal: " + number.ToString("c0");
        Label1.Text += "<br />format decimal value to currency no decimal: " + decimalValue.ToString("c0");
        Label1.Text += "<br />another decimal value to currency no decimal: " + decimalValue2.ToString("c0");
        Label1.Text += "<br />format double to currency no decimal: " + doubleValue.ToString("c0");
        Label1.Text += "<br />another double to currency no decimal: " + doubleValue2.ToString("c0");
        Label1.Text += "<br />another double to currency no decimal: " + doubleValue3.ToString("c0");

        //format string using string.format method.
        Label1.Text += "<br /><br />format decimal value to currency no decimal point: " + string.Format("{0:c0}", decimalValue);
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>c# example - string format currency no decimal</title>  
    <form id="form1" runat="server">  
        <h2 style="color:MidnightBlue; font-style:italic;">  
            c# example - string format currency no decimal
        <hr width="550" align="left" color="Gainsboro" />  
        <br /><br />
            Text="string format currency no decimal"  
More c# examples