sunny123456

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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

复制代码
            //计算比率
            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>
复制代码

 

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

 

 

posted on 2021-01-20 21:24  sunny123456  阅读(1147)  评论(0编辑  收藏  举报