This question already has an answer here:

I want to show how improvement/change has come between two positions in percentage. But I am getting values like this

33.3333333333333333333

How to get fraction part with 2 digits only?

int oldstat = 0;
int newstat = 0;   

if  (oldstat>newstat) 
{
     posStat = "Improved";
     percent = ((decimal)newstat / oldstat)* 100;
     percent =  100 - percent;
     Items[33] = percent.ToString();    
}
else if (oldstat < newstat)
{
     posStat = "Decreased";
     percent = ((decimal)oldstat / newstat) * 100;
     percent = 100 - percent;
     Items[33] = percent.ToString();
}
else if (oldstat == newstat)    
{
     posStat = "No Change";
     percent = 0;
     // percent = percent - 100;
     Items[33] = percent.ToString();
}

Related posts

Recent Viewed