• asp.net 去掉小数点后面多余的0,本身为0还是显示为0


    很多时候,比如gridview内,不想显示从数据库带出的多余小数 ,比如 4.01000, 想显示为 4.01.

    但如果是 0.00000, 想显示为 0 

    那就可以做一个函数:

        /// <summary>
        /// 去掉小数点后多余的0, 0本身显示为0
        /// </summary>
        /// <param name="decimal">传入的数字</param>
        /// <returns>返回值</returns>
        public static string ShortenSurplusZeroBehindDecimalPoint(decimal d)
        {
            return d.ToString("#0.############");
        }

    调用:

    建一个类比如 EBSOBC,上面函数放在这个类中,然后调用它:

    当gridview 显示数据时候:

    EBSOBC.ShortenSurplusZeroBehindDecimalPoint(decimal.Parse(e.Row.Cells[2].Text))

  • 相关阅读:
    C语言01
    C++面试总结更新
    Python网络爬虫与信息提取02
    Self-Driving Car 01
    Python网络爬虫与信息提取01
    Python-03
    Shell
    Python-05
    Python-04
    Python-02
  • 原文地址:https://www.cnblogs.com/cnishop/p/10721877.html
Copyright © 2020-2023  润新知