/// <summary>
        /// Conver decimal  to  different formal string
        /// </summary>
        /// <param name="value">decimal value</param>
        /// <param name="format"></param>
        /// <param name="decimalNumber">保留的小數位數</param>
        /// <returns></returns>
        public static string ToString(this decimal value, CurrencyFormat format, int decimalNumber = 2)
        {
            switch (format)
            {
            case CurrencyFormat.Chinese:
                //ref http://blog.darkthread.net/post-2009-12-23-chinese-number-char.aspx
                var t = EastAsiaNumericFormatter.FormatWithCulture("L", value, null, _twCulture);
                //修正EastAsiaNumericFormatter.FormatWithCulture出現"三百十"之問題,修正為三百一十的慣用寫法
                var res = _regFixOne.Replace(t, m => "壹");
                //拾萬需補為壹拾萬
                if (res.StartsWith("拾"))
                {
                    res = "壹" + res;
                }
                return(res);

            case CurrencyFormat.Comma:
                return(Math.Truncate(value).ToString("N"));     //去小數

            case CurrencyFormat.CommaReservedDecimalNumber:
                return(Math.Round(value, decimalNumber).ToString($"N{ decimalNumber}"));

            default:
                return(value.ToString());
            }
        }
        /// <summary>
        /// 修正EastAsiaNumericFormatter.FormatWithCulture出現"三百十"之問題,
        /// 本函数会将其修正为三百一十的惯用写法
        /// </summary>
        /// <param name="n">要转换的数字</param>
        /// <param name="moneyChar">
        /// 是否使用金额大写,true时使用"一贰参肆...", false时则为"一二三四..."
        /// </param>
        /// <returns>转为中文大写的数字</returns>
        public static string GetChineseToNumber(decimal n, bool moneyChar)
        {
            var t = EastAsiaNumericFormatter.FormatWithCulture(moneyChar ? "L" : "Ln", n, null,
                                                               new CultureInfo("zh-TW"));

            var pattern = moneyChar ? "[^壹貳參肆伍陸柒捌玖]拾" : "[^一二三四五六七八九]十";
            var one     = moneyChar ? "壹" : "一";

            return(Regex.Replace(t, pattern, m => m.Value.Substring(0, 1) + one + m.Value.Substring(1)));
        }
Beispiel #3
0
        internal static string InternalConvert(object arg, NumericConversionDirection direction)
        {
            string format = GetFormatString(direction);

            return(EastAsiaNumericFormatter.FormatWithCulture(format, arg, null, _culture));
        }
Beispiel #4
0
 static void Main(string[] args)
 {
     Console.WriteLine("The representation for number 123.45 in Japanese Standard format is " + EastAsiaNumericFormatter.FormatWithCulture("L", 123.45, null, new CultureInfo("ja")));
 }