C#去掉数字中无效的0,比如186.300 后面的两个0是无效的,可以转换为186.3

具体方法如下,直接上代码:

        /// <summary>
        /// 去除数字中无效的0 如186.300 --> 186.3
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static string RemoveZero(string src)
        {
            if (string.IsNullOrEmpty(src))
                return string.Empty;
            if (src.Contains("."))
            {
                string little = src.Split('.')[1];
                for (int i = little.Length - 1; i >= 0; i--)
                {
                    if (little[i] != '0')
                    {
                        return src.Split('.')[0] + "." + little;
                    }
                    little = little.Remove(i, 1);
                }
                return src.Split('.')[0];
            }
            if (src.Trim() == "-")
            {
                return null;
            }
            return src;
        }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
猜你喜欢
  • 2021-10-22
  • 2022-02-03
  • 2021-05-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案