金额加上逗号标识符 - GetShowCurrencyByStr

2017-02-26 15:21:01  访问(1742) 赞(0) 踩(0)


        /// <summary>
        /// 金额加上逗号标识符 - GetShowCurrencyByStr
        /// </summary>
        /// <param name="strValue"></param>
        /// <returns></returns>
        public static string GetShowCurrencyByStr(string strValue)
        {
            return GetShowCurrencyByStr(strValue, ",");
        }

        /// <summary>
        /// 金额加上逗号标识符 - GetShowCurrencyByStr
        /// </summary>
        /// <param name="strValue"></param>
        /// <param name="splitChar"></param>
        /// <returns></returns>
        public static string GetShowCurrencyByStr(string strValue, string splitChar)
        {
            if (strValue == null || strValue == "")
                return "";

            int charIdx = strValue.IndexOf('.');

            string leftValue = "";

            if (charIdx != -1)
            {
                leftValue = strValue.Substring(charIdx);
            }

            int iLen = strValue.Length;

            string theResult = "";

            int idx = 0;

            for (int i = iLen - 1; i >= 0; --i)
            {
                ++idx;

                if (idx != 1 && idx % 3 == 1)
                    theResult = splitChar + theResult;

                theResult = strValue[i].ToString() + theResult;
            }

            theResult += leftValue;

            return theResult;
        }


标签:金额加上逗号标识符 - GetShowCurrencyByStr 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)