internal string ConvertToLocalizedText(Decimal num) { StringBuilder text = new StringBuilder(); StackWithIndex stack = new StackWithIndex(); if (num < new Decimal(0)) { text.Append(this.Minus); num = Math.Abs(num); } num = this.Initialize(num); if ((long)(ulong)num == 0L) { text.Append(this.Zero); } else { this.GetIntegralStack(Math.Truncate(num), 1UL, stack); this.ConvertIntergralStackToText(stack, text); } num -= Math.Truncate(num); if (num != new Decimal(0)) { text.Append(this.DecimalPoint); this.GetDecimalText(num, text); } return(text.ToString()); }
protected override void ConvertIntergralStackToText(StackWithIndex stack, StringBuilder text) { string str1 = string.Empty; bool flag = true; while (stack.Count > 0) { string str2 = stack.Pop(); if (str2 == this.Zero) { if (!flag) { str1 = this.Zero; } flag = true; } else if (str2 == this.TenThousand || str2 == this.HundredMillion || str2 == this.ThousandBillion) { text.Append(str2); str1 = string.Empty; flag = false; } else if (!string.IsNullOrEmpty(str2)) { text.Append(str1); text.Append(str2); str1 = string.Empty; flag = false; } } }
protected override void ConvertIntergralStackToText(StackWithIndex stack, StringBuilder text) { while (stack.Count > 0) { string str = stack.Pop(); text.Append(str); } }
protected override void ConvertIntergralStackToText(StackWithIndex stack, StringBuilder text) { while (stack.Count > 0 && stack.Peek() == this.Zero) { stack.Pop(); } while (stack.Count > 0) { text.Append(stack.Pop()); } }
protected override void ConvertIntergralStackToText(StackWithIndex stack, StringBuilder text) { while (stack.Count > 0) { string str = stack.Pop(); text.Append(str); } if ((int)text[text.Length - 1] != 32) { return; } text.Remove(text.Length - 1, 1); }
protected override void ConvertIntergralStackToText(StackWithIndex stack, StringBuilder text) { while (stack.Count > 0 && string.IsNullOrEmpty(stack.Peek())) { stack.Pop(); } bool flag = false; if (stack.Peek().Equals(this.Digits[1])) { for (int index = 2; index < stack.Count && string.IsNullOrEmpty(stack[index]); ++index) { if (index == stack.Count - 1) { flag = true; } } } else { flag = false; } while (stack.Count > 0) { string str = stack.Pop(); if (!string.IsNullOrEmpty(str)) { if (flag) { flag = false; } else if (!str.StartsWith(this.Digits[1]) || !str.EndsWith(this.Ten) && !str.EndsWith(this.Hundred) && !str.EndsWith(this.Thousand)) { text.Append(str); } else { text.Append(str.Substring(this.Digits[1].Length)); } } } if ((int)text[text.Length - 1] != 32) { return; } text.Remove(text.Length - 1, 1); }
/// <summary> /// Splits the number. /// Pushs every digit and its digitWeight into stack. /// </summary> /// <param name="num">the number needed to be splited.</param> /// <param name="position">Splits the number from this position.</param> /// <param name="stack">Pushs every digit and its digitWeight this stack.</param> protected virtual void GetIntegralStack(Decimal num, ulong position, StackWithIndex stack) { if (num < new Decimal(10000)) { if (num != new Decimal(0) || (long)position == 1000000000000L) { stack.Push(this.GetPositionText(position)); } for (int index = 0; index < 4; ++index) { int digit = (int)(num % new Decimal(10)); ulong position1 = (ulong)Math.Pow(10.0, (double)index); num /= new Decimal(10); stack.Push(this.GetDigitText(digit, position1)); } } else { this.GetIntegralStack(Math.Truncate(num % new Decimal(10000)), position, stack); this.GetIntegralStack(Math.Truncate(num / new Decimal(10000)), position * 10000UL, stack); } }
/// <summary> /// Converts the digit information from the stack into a StringBuilder. /// </summary> /// <param name="stack">Stores the digits needed to be transfered.</param> /// <param name="text">Transfers the digits to this text.</param> protected abstract void ConvertIntergralStackToText(StackWithIndex stack, StringBuilder text);