Display textbox value as decimal from Code behind as "10.20"

Sathya4260
Posted by Sathya4260 under C# category on | Points: 40 | Views : 11384
Hi,

Here is the simple code the show the text box values in the format 0.00

Let take textbox1, I am going to do some calculation and display the output in the format 0.00
Double a=10.2;
Double b=10;
Double sum=a+b;
textbox1.Text=sum.ToString("N2");

or

textbox1.Text=sum.ToString("#0.00");

Output : 20.20

Comments or Responses

Posted by: T.saravanan on: 3/9/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi Sathish Kumar S,

Nice...
But small correction in your code..
textbox1.Text =sum.ToString("N2"); 

textbox1.Text =sum.ToString("#0.00");

Because C# is Case Sensitive Language.
Posted by: Sathya4260 on: 3/10/2011 Level:Starter | Status: [Member] | Points: 10
Thanks for reminding...

I think we r not going to compile the code here itself, anyway IntelliSense would do for us to write the correct code

Just for fun...
Posted by: T.saravanan on: 3/10/2011 Level:Silver | Status: [Member] [MVP] | Points: 10
Of course we can not compile the code here.If any one copy a code and paste into Visual Studio then compile means its thrown error.Then only i suggest the correction...

Login to post response