ankur
ankur

Reputation: 4733

Find percentage and rounding it two places

I know this is basic one I'm asking, bear with me.

I'm trying to find out the percentage.

This is what I'm trying, but it is giving me an error of ambiguous call.

int total = 1;
int totalUsers = 3;
if (totalUsers > 0)
{
    var per =Math.Round(total / totalUsers,4) * 100 ;
    object[] args = new object[] { total, totalUsers, per };
    lblMsg.Text = string.Format("{0} of {1} users already voted({2}%)", args);
}

 

For Example:
if total = 1
totalusers = 3 
per should be after rounding of 33.33%

Upvotes: 0

Views: 84

Answers (1)

L.B
L.B

Reputation: 116118

To resolve the ambiguous call error, change to:

var per =Math.Round((decimal)total / totalUsers,4) * 100 ;

Upvotes: 1

Related Questions