模拟游戏中相乘减伤计算
static void Test() { Calc(new double[] { 0.1,0.3,0.2,0.17,0.5 }); } static void Calc(double[] arr) { double total = 1; foreach (var d in arr) { total *= (1 - d); Console.WriteLine($"减伤:{d:P}"); //ToString("P4") 转成百分比保留4个小数位 } Console.WriteLine($"总减伤:{1 - total:P} 相当于{1 / total:F}倍生命值"); //ToString("F4") 精确4个小数位 }
标签:arr,百分比,Console,C#,double,小数点,total,小数 From: https://www.cnblogs.com/luludongxu/p/17354832.html