CommonUtil.cs 817 B

12345678910111213141516171819202122232425262728
  1. namespace Admin.NET.Core;
  2. /// <summary>
  3. /// 通用工具类
  4. /// </summary>
  5. public static class CommonUtil
  6. {
  7. /// <summary>
  8. /// 生成百分数
  9. /// </summary>
  10. /// <param name="PassCount"></param>
  11. /// <param name="allCount"></param>
  12. /// <returns></returns>
  13. public static string ExecPercent(decimal PassCount, decimal allCount)
  14. {
  15. string res = "";
  16. if (allCount > 0)
  17. {
  18. var value = (double)Math.Round(PassCount / allCount * 100, 1);
  19. if (value < 0)
  20. res = Math.Round(value + 5 / Math.Pow(10, 0 + 1), 0, MidpointRounding.AwayFromZero).ToString();
  21. else
  22. res = Math.Round(value, 0, MidpointRounding.AwayFromZero).ToString();
  23. }
  24. if (res == "") res = "0";
  25. return res + "%";
  26. }
  27. }