调用 ConvertMoney的ConvertMoneyToWords(decimal money)方法即可

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
namespace Common
{
public class ConvertMoney
{
static string[] c_Num = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
static string[] c_FH = { "", "拾", "佰", "仟" };
static string[] c_Wn = { "圆", "万", "亿" };
public static string ConvertMoneyToWords(decimal money)
{
string result = string.Empty;
if (!string.IsNullOrEmpty(money.ToString()))
{
string[] moneysplit = money.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
Regex reg = new Regex("零{2,}");
string m = moneysplit[];
int mlen = m.Length;
string word = string.Empty;
for (int i = mlen; i > ; i--)
{
word = ConverNumToWord(word, m[mlen - i], i, true);
}
if (moneysplit.Length > )
{
string d = moneysplit[];
int dlen = d.Length > ? : d.Length;
if (dlen == && d[] == '' && d[] == '')
{
word += "整";
}
else
{
for (int i = ; i < dlen; i++)
{
word = ConverNumToWord(word, d[i], i, false);
}
}
}
else
{
word += "整";
}
result = reg.Replace(word.ToString(), "零");
}
return result;
}
private static string ConverNumToWord(string appendStr, char a, int index, bool isYuan)
{
string s = c_Num[Convert.ToInt32(a) - ];
if (isYuan)
{
int z = (index - ) / ;
int y = (index - ) % ;
appendStr = appendStr + s + (s != "零" ? c_FH[y] : "");
if (y == )
{
appendStr = appendStr.Trim('零') + c_Wn[z];
}
}
else
{
if (index == && s != "零")
{
appendStr = appendStr + s + "角";
}
else if (index == )
{
appendStr = appendStr + s;
}
if (index == && s != "零")
{
appendStr = appendStr + s + "分";
}
}
return appendStr;
}
}
}

C# 金钱 小写转大写的算法的更多相关文章

  1. recurse_array_change_key_case()递规返回字符串键名全为小写或大写的数组

    //递归返回字符串键名全为小写或大写的数组function recurse_array_change_key_case(&$input, $case = CASE_LOWER){    if( ...

  2. 自定义EL函数:小写转大写

    1,定义java静态方法,FunctionDemo,有小写转大写的功能 package com.itheima.domain; public class FunctionDemo { public s ...

  3. java网络编程(6)——实现一个服务器把小写转大写

    实现一个服务器,通过我们发送的文本数据,然后转回大写放回,实现一个服务端与客户端的交互,用over来作为结束标记,具体代码如下: 客户端: package com.seven.tcp; import ...

  4. 批量将PowerDesigner中表字段由小写变成大写

    通过以下VB脚本即可批量修改,在Tools=>Execute Commands下的Edit/Run Scripts,或者通过Ctrl+Shift+X运行以下脚本即可: '************ ...

  5. C# 字符串大写转小写,小写转大写,数字保留,其他除外

    又是一道面试题,我只想到两种方式: 第一种:循环字符串,判断每个字符串的类型,再根据类型对该字符进行操作(转大写.转小写.不变或舍弃) static void Main(string[] args) ...

  6. ABAP-金额小写转大写

    FUNCTION ZSDI0007_CH_LOWERTOUPPER. *"---------------------------------------------------------- ...

  7. vue 如何将输入框的输入自动小写转大写(使用 v-model 时采取另一种方式)

    前言:小写转大写,可以用过滤器实现,但当使用 v-model 时就不行了,这里有解决方案.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9289205.html ...

  8. python把指定目录下的递归所有目录和文件名转换成小写或大写

    cat convert.py #!/usr/bin/env python # -*- coding:utf-8 -*- import os, sys def convert(rootdir, opty ...

  9. js helper(hsv/hsb转rgb颜色,uuid,金额小写转大写)

    hsv/hsb转rgb颜色 //h:[0,360],s:[0,100],v:[0,100] //return r:[0,256], g:[0,256],b:[0,256] function hsvto ...

随机推荐

  1. 配置本机IIS服务器

    1.控制面板---程序---(程序和功能) 安装完成之后就可以访问本地的localhost 2.进入防火墙界面--高级设置 至此开放端口完成

  2. LAMP(1) 在VirtualBox里安装Ubuntu Server

    问题0.虚拟机中安装lamp环境 问题解决: 来自百度经验 问题1. 用putty远程登陆linux系统,显示network error connection refused 问题解决 问题2. my ...

  3. windows使用git时出现:warning: LF will be replaced by CRLF

    windows中的换行符为 CRLF, 而在linux下的换行符为LF,所以在执行add . 时出现提示: 执行以下代码 $ rm -rf .git // 删除.git $ git config -- ...

  4. Resource leak: 'context' is never closed

    from: http://stackoverflow.com/questions/14184059/spring-applicationcontext-resource-leak-context-is ...

  5. CentOS 7网卡网桥、绑定设置

    一.网卡桥接设置: 1.网卡配置文件: [root@localhost /]# vim /etc/sysconfig/network-scripts/ifcfg-enp8s0 TYPE=Etherne ...

  6. BZOJ4539: [Hnoi2016]树

    复制的树缩点,主席树查k小,毫无技术含量,纯码农题. #include<bits/stdc++.h> #define u first #define v second #define F ...

  7. ThinkPHP框架之验证码

    Think\Verify类可以支持验证码的生成和验证功能. 下面是最简单的方式生成验证码: $Verify = new \Think\Verify(); $Verify->entry(); 上面 ...

  8. webapi-创建项目

  9. mysql 关系表 分组读取的方法

    关系表 是一个一对多的表 我们用的时候往往希望得到 array( a=>array(1,2,3,4....), b=>array(3,4,5,6,7...) ) 这样的数组 所以我们可以使 ...

  10. Apache Shiro 学习记录2

    写完上篇随笔以后(链接).....我也想自己尝试一下写一个Strategy.....Shiro自带了3个Strategy,教程(链接)里作者也给了2个.....我想写个都不一样的策略.....看来看去 ...