示例#1
0
        /// <function>NumUtil.AddComma</function>
        /// <summary>add thousand comm to a number string</summary>
        /// <param name="strNum"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string AddComma(string strNum)
        {
            if (strNum == null || strNum.Length == 0)
            {
                return(strNum);
            }

            int    intLength = 0;
            string num       = "";
            string number    = StrUtil.Trim(strNum);
            int    dotIdx    = number.IndexOf(".");

            if (dotIdx >= 0)
            {
                num    = number.Substring(dotIdx);
                number = number.Substring(0, dotIdx);
            }
            intLength = number.Length;
            for (int i = 1; i <= intLength / 3; i++)
            {
                number = number.Insert(intLength - i * 3, ",");
            }
            if (number.Length > 1)
            {
                if (number.Substring(0, 1).Equals(","))
                {
                    number = number.Substring(1);
                }
            }
            return(number + num);
        }
示例#2
0
        /// <summary>
        /// 如果字符串不是数字,返回0
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static long TryGetVal_Long(object o)
        {
            string str = o == null ? "" : StrUtil.Trim(o.ToString());

            if (str.Length == 0)
            {
                return(0);
            }
            if (!IsDemical(str, NumberFormat_Comma))
            {
                return(0);
            }
            return(GetVal_Long(str));
        }
示例#3
0
        /// <summary>
        /// 如果字符串不是数字,返回0
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public static decimal TryGetVal(object o)
        {
            string str = o == null ? "" : StrUtil.Trim(o.ToString().Replace("(", "").Replace(")", ""));

            if (str.Length == 0)
            {
                return(0);
            }
            if (!IsDemical(str, NumberFormat_Comma))
            {
                return(0);
            }
            return(GetVal(str));
        }