Re: C # question

  • From: Varun Khosla <varun.lists@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 7 Dec 2009 10:52:30 +0530

Hi Ceilia,

The ToString method of the Decimal class can take format parameter and
there are many built-in formats including for displaying currency.
The method is overloaded and I'll tell u one that takes a string parameter.

ToString(String format)
For currency, the format is C[num] where num specifies, in integer,
how many digits to display after the decimal point.

decimal d = 2.00;
textbox.Text = d.ToString("C"); // Outputs $2
textbox.Text = d.ToString("C2"); // Outputs $2.00

HTH


On 12/6/09, Celia Rodriguez <celia-rodriguez@xxxxxxxxxxxxx> wrote:
> HiVarun
>
>
>
> How do I display a decimal integer into a text box or label?
>
>
>
> Here is my simple code:
>
>
>
> Decimal TotalCost = 0;
>
>
>
> TotalCost+=2.00M;
>
>
>
> I want to display TotalCost  as $ 2.00 in
>
> ,Either
>
> lblTotal.Text or
>
> TxtTotal.Text
>
> But I keep getting the following error.
>
> Error  1              Cannot implicitly convert type 'decimal' to 'string'
>
>
> Also how do I convert 2.00 as $ 2.00?
>
>
>
> Thank You,
>
> Celia
>
>


-- 
Varun
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: