Example #1
0
        private static string ToRMB_(decimal num, string digits, string units, string err)
        {
            string _str = num.ToString("F2");
            STR    _s   = new STR();

            if (_str[0] == '-')
            {
                _s  += units[15];
                _str = _str.TrimStart('-');
            }

            string[] _parts = _str.Split('.');

            int _intLen = _parts[0].Length;

            if (_intLen > 12)
            {
                return(err);
            }
            bool _int0 = _parts[0] == "0";
            bool _dec0 = _parts[1] == "00";

            int  i, j, x, n = 0;
            bool _0 = false, _j0 = false;

            if (_int0 && _dec0)
            {
                _s += digits[0];
                _s += units[1];
            }
            else if (!_int0)
            {
                // 处理整数部分
                for (i = 0; i < _intLen; i++)
                {
                    n = Convert.ToInt32(_parts[0][i]) - 48;
                    x = _intLen - i;
                    // j = 0 时为段尾
                    j = (x - 1) & 0x3;

                    // 处理 0
                    if (n == 0)
                    {
                        _0 = true;
                        // 处理为段尾的 0
                        if (j == 0)
                        {
                            if (_intLen == 1 && _dec0)
                            {
                                _s += digits[0];
                            }
                            if (_j0 || x == 1)
                            {
                                _s += units[x];
                            }
                            _j0 = false;
                        }
                    }
                    // 处理非 0
                    else
                    {
                        if (_0)
                        {
                            _s += digits[0];
                            _0  = false;
                        }
                        _s += digits[n];
                        _s += units[x];

                        // 如果是段尾,设置非 0 标志
                        _j0 = j == 0 ? false : true;
                    }
                }
            }

            // 处理小数部分
            // 如果没有小数,添加"整"字符
            if (_dec0)
            {
                _s += units[0];
            }
            else
            {
                int g = n;

                // 角
                n = Convert.ToInt32(_parts[1][0]) - 48;
                if (n != 0)
                {
                    _s += digits[n];
                    _s += units[13];
                }
                else if (_intLen != 1 || g != 0)
                {
                    _s += digits[0];
                }

                // 分
                n = Convert.ToInt32(_parts[1][1]) - 48;
                if (n != 0)
                {
                    _s += digits[n];
                    _s += units[14];
                }
                else
                {
                    _s += units[0];
                }
            }

            return(_s.ToString());
        }
Example #2
0
 /// <summary>使用指定的另一个实例初始化新 <see cref="STR" /> 实例</summary>
 /// <param name="value">用于初始化实例值的另一个实例</param>
 public STR(STR value)
 {
     this.__SB = value.__SB;
 }
Example #3
0
 /// <summary>在此实例的结尾追加另一个实例指定子字符串的副本</summary>
 /// <param name="value">包含要追加的另一个实例</param>
 /// <param name="startIndex">value 中子字符串开始的位置</param>
 /// <param name="charCount">value 中要追加的字符数</param>
 /// <returns>此字符串处理实例</returns>
 public STR Append(STR value, int startIndex, int charCount)
 {
     this.__SB.Append(value.__SB.ToString(), startIndex, charCount);
     return(this);
 }
Example #4
0
 /// <summary>在此实例的结尾追加另一个实例的字符串表示形式</summary>
 /// <param name="index">此实例中开始插入的位置</param>
 /// <param name="value">要插入的值</param>
 /// <returns>此字符串处理实例</returns>
 public STR Insert(int index, STR value)
 {
     this.__SB.Insert(index, value.__SB.ToString());
     return(this);
 }
Example #5
0
 /// <summary>在此实例的结尾追加另一个实例的字符串表示形式</summary>
 /// <param name="value">要追加的值</param>
 /// <returns>此字符串处理实例</returns>
 public STR Append(STR value)
 {
     this.__SB.Append(value.__SB.ToString());
     return(this);
 }