C# 计算百分比

https://www.cnblogs.com/enych/p/10298396.html

C# 计算百分比
            //计算比率
            decimal A =(decimal) 200.20; 
            decimal B = (decimal)1000.20; 
        </span><span style="color: rgba(0, 0, 255, 1)">decimal</span> t = <span style="color: rgba(0, 0, 255, 1)">decimal</span>.Parse((A/B).ToString(<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">0.000</span><span style="color: rgba(128, 0, 0, 1)">"</span>)) ; <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">保留3位小数
        </span><span style="color: rgba(0, 128, 0, 1)">//

var t1 = Math.Round(t, 2); //四舍五入,精确2位

        <span style="color: rgba(0, 0, 255, 1)">var</span> t2 = t1 * <span style="color: rgba(128, 0, 128, 1)">100</span>;  <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">乘以100     x100结果%</span></pre>
C# 计算百分比

 

      var t3 = Math.Floor(Math.Round(decimal.Parse((0 / 100).ToString("0.000")), 2) * 100);

 

 

上一篇:更强更方便的进制转换工具


下一篇:Ksql中如何进行正确的四舍五入