function GetPercentnum, total) { /// <summary> /// 求百分比 /// </summary> /// <param name="num">当前数</param> /// <param name="total">总数</param> num = parseFloatnum); total = parseFloattotal); if isNaNnum) || isNaNtotal)) { return "-"; } return total <= 0 ? "0%" : Math.roundnum / total * 10000) / 100.00)+"%"; }
使用方法如下:
GetPercent1,100);
结果:
1%;