zoukankan      html  css  js  c++  java
  • c#实现高精度四舍五入

       /// <summary>
            /// 實現數據的四捨五入
            /// </summary>
            /// <param name="colValue">四捨五入的值</param>
            /// <param name="dataScale">小數點位數</param>
            /// <returns></returns>
            private static string DataRound(double colValue, int dataScale)
            {
                string res = string.Empty;
                //實現四捨五入
                colValue = Math.Round(colValue, Convert.ToInt32(dataScale), MidpointRounding.AwayFromZero);
                res = colValue.ToString("G");
                //按精度獲取準確值
                if (res.Split('.').Length >= 2)
                {
                    if (res.Split('.')[1].Length < dataScale)
                    {
                        res = res.PadRight(dataScale - res.Split('.').Length, '0');
                    }
                    else
                    {
                        res = res.Substring(2, dataScale);
                    }
                }
                else
                {
                    res += ".";
                    res = res.PadRight(dataScale+2, '0');
                }
                return res;
            }

  • 相关阅读:
    ES6学习笔记<一> let const class extends super
    js_字符转Unicode
    (转)利用 SVG 和 CSS3 实现有趣的边框动画
    事件委托
    模拟操作
    jQUery动画
    jQUery事件
    jQuery的单选,复选,下拉
    jQuery中对属性的增删改查
    jQuery中其他
  • 原文地址:https://www.cnblogs.com/xiatianoo/p/4789307.html
Copyright © 2011-2022 走看看