zoukankan      html  css  js  c++  java
  • 把阿拉伯数字转换为中文金额数字:123→壹佰贰拾三圆

    把阿拉伯数字转换为中文金额数字:123→壹佰贰拾三圆
    static void ZHuan(int num)
            {
                string[] nums = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
                string[] wei = { "", "", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "亿", "拾", "佰", "仟", };
                if (num < 0)
                {
                    throw new Exception("num不能为负数!");
                }
                string num1 = Convert.ToString(num);
                int len = num1.Length;
                string tmps, sb;
                sb = "";
                int i;
                for ( i= 1; i <= len; i++)
                {
                    tmps = num1.Substring(len - i, 1);
                    //sb = nums[Int32.Parse(tmps)] + wei[i] + sb;
                    sb= string.Concat(nums[Int32.Parse(tmps)] + wei[i], sb);
                }
                sb= sb.Replace("零拾", "零").Replace("零佰", "零").Replace("零仟", "零");
                for (i = 1; i <= 6; i++)
                {
                    sb = sb.Replace("零零", "零");
                }
                sb=sb.Replace("零萬", "萬").Replace("零億", "億").Replace("零零", "零");
                sb += "圆整";
                sb = sb.Replace("零圆", "圆");
                Console.WriteLine(sb);

            }

    愿你我既可以朝九晚五,也可以浪迹天涯;愿你我既可以拈花把酒,也能围炉诗书茶。
  • 相关阅读:
    例题6-8 Tree Uva548
    例题6-7 Trees on the level ,Uva122
    caffe Mac 安装
    Codeforces Round #467 (Div. 1) B. Sleepy Game
    Educational Codeforces Round37 E
    Educational Codeforces Round 36 (Rated for Div. 2) E. Physical Education Lessons
    Good Bye 2017 E. New Year and Entity Enumeration
    Good Bye 2017 D. New Year and Arbitrary Arrangement
    Codeforces Round #454 D. Seating of Students
    浙大紫金港两日游
  • 原文地址:https://www.cnblogs.com/xiaoheihei/p/8149277.html
Copyright © 2011-2022 走看看