using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace iWareCommon.Utils
{
///
/// C#帮助类
///
public class CSharpHelper
{
///
/// 求百分比方法
///
///
///
///
public static string ExecPercent(decimal PassCount, decimal allCount)
{
string res = "";
if (allCount > 0)
{
res = ChinaRound((double)Math.Round(PassCount / allCount * 100, 1), 0).ToString() + "%";
}
return res;
}
///
/// 求百分比方法
///
///
///
///
public static int ExecPercentRetInt(decimal PassCount, decimal allCount)
{
if (allCount > 0)
{
return Convert.ToInt32(ChinaRound((double)Math.Round(PassCount / allCount * 100, 1), 0));
}
return 0;
}
private static double ChinaRound(double value, int decimals)
{
if (value < 0)
{
return Math.Round(value + 5 / Math.Pow(10, decimals + 1), decimals, MidpointRounding.AwayFromZero);
}
else
{
return Math.Round(value, decimals, MidpointRounding.AwayFromZero);
}
}
}
}