Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,


I have problem that when i get the result like 0.67543 i want that result like 0.67 only. means there is only 2 number show after (.) dot

here is my code

C#
float calc = 0;
float lenght=0, breadth=0, height=0;
lenght = float.Parse(txtlenght.Text);
breadth = float.Parse(txtbreath.Text);
height = float.Parse(txtheight.Text);
calc = ((lenght * breadth * height) / 6000);

calc = Convert.ToInt32((float)Math.Round(calc, 3));

if (calc != 0)
{
    lblresult.Text = "Your Volumetric Weight is :  " + calc.ToString() + "Kg.";
}
Posted

Try:
C#
lblresult.Text = "Your Volumetric Weight is :  " + calc.ToString("0.00") + "Kg.";
 
Share this answer
 
Comments
OriginalGriff 28-Jul-12 3:40am    
You're welcome!

BTW: don't automatically call people "dear" on the internet. It's a cultural thing but it can be taken as patronising if the person you are talking to is female - and you never know on the internet! Best to just leave it out completely.
Yatin chauhan 30-Jul-12 1:20am    
Oky Me Sorry..!!!
OriginalGriff 30-Jul-12 3:31am    
No problem - it doesn't bother me, but it can bother others.
lblresult.Text = "Your Volumetric Weight is : " + calc.ToString("###,###.000")+ "Kg.";
 
Share this answer
 
Comments
Yatin chauhan 28-Jul-12 3:29am    
Thank For Reply ....

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