Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am having an textbox in which value is passed from code behind,If i pass the value as 8 it should display as 8.00, as of now if i pass 5.2 it displays as it is.

Actually i am doing an calculation and output is displayed in textbox

Kindly help to solve this

Thanks in advance...
Posted

This way, the number will always have two decimal places.

double myNum = 5;
TextBox1.Text = myNum.ToString("N2");


Output:
5.00
 
Share this answer
 
Comments
sathya4260 7-Mar-11 5:28am    
It works fine,

Thanks for timely reply,Add 5 to ur count
Ryan Zahra 7-Mar-11 5:40am    
Thanks :)
Also check this. If .ToString("N2") is used you will get a comma like 1,234.00
C#
 double myNum = 1234;
TextBox1.Text=myNum.ToString("#0.00")


output: 1234.00
 
Share this answer
 
Comments
rajivpande86 7-Mar-11 16:28pm    
glad to know the difference..tak my 5 !!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900