C#-Doubel类型的文本金额转换成人民币

/// <summary>
        /// 将数字转换成人民币
        /// </summary>
        /// <param name="Value"></param>
        public static string DoubleToMoney(string Value)
        {
            double valu;
            string j="", f="";
            if (double.TryParse(Value, out valu))
            {
                int valua = (int)valu;
                int i = Value.IndexOf('.');
                if (i>=0) {
                    if (Value.IndexOf('.') + 2 <= Value.Length) {
                        j = Value.Substring(Value.IndexOf('.') + 1, 1);
                    }
                    if (Value.IndexOf('.') +3 <= Value.Length) {
                        f = Value.Substring(Value.IndexOf('.') + 2, 1);
                    }
                }
                if ((j == "0" || j == "") && (f == "0" || f == ""))
                {
                    return $"{valua.ToString()}元";
                }
                if (f == "0" || f == "")
                {
                    return $"{valua.ToString()}元{j}角";
                }
                return $"{valua.ToString()}元{j}角{f}分";
            }
            else
            {
                return "";
            }
        }


posted @ 2018-05-25 10:40  Magical-Conch  阅读(40)  评论(0编辑  收藏  举报