查找百分比并将其四舍五入

时间:2012-11-02 07:05:57

标签: c# ambiguous

我知道这是我要问的基本问题,请耐心等待。

我正试图找出百分比。

这就是我正在尝试的,但它给了我一个模糊呼叫的错误。

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%

1 个答案:

答案 0 :(得分:1)

要解决ambiguous call错误,请更改为:

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