| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 663 人关注过本帖, 1 人收藏
标题:怎样让数字转为货币形式???
只看楼主 加入收藏
lelejiayou
Rank: 1
来 自:宁海
等 级:新手上路
帖 子:73
专家分:0
注 册:2013-3-20
结帖率:73.68%
收藏(1)
已结贴  问题点数:10 回复次数:7 
怎样让数字转为货币形式???
比如:123为壹佰贰拾叁圆整
搜索更多相关主题的帖子: 数字 
2013-04-23 22:13
Susake
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:女儿国的隔壁
等 级:贵宾
威 望:23
帖 子:2288
专家分:6481
注 册:2012-12-14
收藏
得分:4 
..kk

仰望星空...........不忘初心!
2013-04-23 22:14
Aviva_Wang
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:苏州
等 级:贵宾
威 望:26
帖 子:701
专家分:2382
注 册:2013-3-12
收藏
得分:4 
好像没有现成的吧,要自己写方法的

asp
2013-04-23 22:26
Susake
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:女儿国的隔壁
等 级:贵宾
威 望:23
帖 子:2288
专家分:6481
注 册:2012-12-14
收藏
得分:0 
用 枚举enum

仰望星空...........不忘初心!
2013-04-23 22:33
lelejiayou
Rank: 1
来 自:宁海
等 级:新手上路
帖 子:73
专家分:0
注 册:2013-3-20
收藏
得分:0 
可以举个例子吗??我自己也在想,
2013-04-23 23:21
Susake
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:女儿国的隔壁
等 级:贵宾
威 望:23
帖 子:2288
专家分:6481
注 册:2012-12-14
收藏
得分:0 
enum MyEnum
{
张三 = 1;
李四 = 2;
}
大概是这样,我不会C#

仰望星空...........不忘初心!
2013-04-23 23:26
lxb932979339
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:84
专家分:313
注 册:2013-4-24
收藏
得分:4 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!IsNum(textBox1.Text.Trim()))
            {
                MessageBox.Show("你输入的不是数字,请重新输入!!");
                textBox1.Focus();
                return;
            }
            textBox2.Text = ChangeToNew(textBox1.Text);
        }
        public bool IsNum(string str)//判断输入的字符是不是数字
        {
            return System.Text.RegularExpressions.Regex.IsMatch(str, @"^[0-9]*$");
        }
      
        public string ChangeToChar(string str)
        {
            string ch = "零";

            switch (str)
            {
                case "0": ch = "零";
                    break;
                case "1": ch = "壹";
                    break;
                case "2": ch = "贰";
                    break;
                case "3": ch = "叁";
                    break;
                case "4": ch = "肆";
                    break;
                case "5": ch = "伍";
                    break;
                case "6": ch = "陆";
                    break;
                case "7": ch = "柒";
                    break;
                case "8": ch = "捌";
                    break;
                case "9": ch = "玖";
                    break;
            }
            return ch;
        }
        public int NumBase(int length)
        {
            int j = 10;
            for (int i = 0; i <length; i++)
            {
                if (i == 0)
                {
                    j = 1;
                }
                else if (i == 1)
                {
                    j = 10;
                }
                else
                {
                    j = j * 10;
                }
            }
            return j;
        }
        public string ChangeToNew(string str)
        {
            int NumLength = str.Length;
            StringBuilder sb = new StringBuilder();
            int numStr = 0;
            try
            {
                numStr = int.Parse(str.Trim());
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            int numTemp = 0;
            for (int i = NumLength ; i>0; i--)
            {
                int j = numStr / NumBase(i);
                numTemp = numStr;
                numStr = numTemp - j * NumBase(i);
                string g = ChangeToChar(j.ToString ());
                switch (i)
                {
                    case 0: sb.Append(g); break;
                    case 1: sb.Append(g + "元整"); break;
                    case 2: sb.Append(g+"十"); break;
                    case 3: sb.Append(g+"百"); break;
                    case 4: sb.Append(g + "千"); break;
                    case 5: sb.Append(g + "万"); break;
                    case 6: sb.Append(g + "十"); break;
                    case 7: sb.Append(g + "百"); break;
                    case 8: sb.Append(g + "千"); break;
                    case 9: sb.Append(g + "亿"); break;
                    case 10: sb.Append(g + "十"); break;
                    case 11: sb.Append(g + "百"); break;
                    case 12: sb.Append(g + "千"); break;
                    case 13: sb.Append(g + "兆"); break;

                }
            }
            return sb.ToString();

        }
    }
}
2013-04-25 01:04
lelejiayou
Rank: 1
来 自:宁海
等 级:新手上路
帖 子:73
专家分:0
注 册:2013-3-20
收藏
得分:0 
非常感谢你。。。
2013-04-26 08:11
快速回复:怎样让数字转为货币形式???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019158 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved