using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace iWareCommon.Utils
|
{
|
/// <summary>
|
/// C#帮助类
|
/// </summary>
|
public class CSharpHelper
|
{
|
/// <summary>
|
/// 求百分比方法
|
/// </summary>
|
/// <param name="PassCount"></param>
|
/// <param name="allCount"></param>
|
/// <returns></returns>
|
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;
|
}
|
|
/// <summary>
|
/// 求百分比方法
|
/// </summary>
|
/// <param name="PassCount"></param>
|
/// <param name="allCount"></param>
|
/// <returns></returns>
|
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);
|
}
|
}
|
}
|
}
|