调用 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. Android基础测试题(四)

    看了前两道题大家有没有发现,测试题少了(一),大家猜猜测试题(一)是什么? Android基础测试题(四): 需求: 建一个方法,格式化输出2016-11-14 10:15:26格式的当前时间,然后截 ...

  2. iOS持续写文件到本地

    NSString *tempSavePath = [NSString stringWithFormat:@"%@/Documents",kDocumentPath]; NSFile ...

  3. C#面向对象设计模式纵横谈——1.面向对象设计模式与原则

    一:设计模式简介 每一个模式描述了一个在我们周围不断重复发生的问题,以及该问题的解决方案的核心. ---- Christopher Alexander 软件设计领域设计模式: 设计模式描述了软件设计过 ...

  4. 【poj3270】 Cow Sorting

    http://poj.org/problem?id=3270 (题目链接) 题意 n个数要要按从小到大的顺序排列,每次只能交换任意两个数,交换的代价为这两个数之和,问最小代价. Solution 题目 ...

  5. 推荐一款Mac上好用的Markdown编辑器

    [TOC] 推荐一款Mac上好用的Markdown编辑器 正文 我算是一位Evernote的重度用户吧.之前也尝试过为知笔记,有道云笔记,微软的onenote,最后还是觉的Evernote.因为我喜欢 ...

  6. UVA445

    测试了很多数据都没问题,但是就是一直WA... #include<stdio.h> #include<string.h> int main(){ ]; int n; while ...

  7. php 远程本地化无后缀图片

    $body = '<p style="margin: 0px 0px 1.1em; padding: 0px; color: rgb(51, 51, 51); font-family: ...

  8. IIS7.5使用web.config设置伪静态的二种方法

    转自 网上赚钱自学网 .http://www.whosmall.com/post/121 近几天公司里开发的项目有几个运行在IIS7.5上,由于全站采用的是伪静态,因此从网上找到两两种方法来实现.这两 ...

  9. python之登录小程序

    # 登录操作 PassWord_list = [] Reset_pw = '*#*#' def account_login(): if PassWord_list == []: PassWord = ...

  10. JS学习笔记(不断更新)

    1 基础知识 为什么学习 JavaScript? JavaScript web 开发人员必须学习的 门语言中的一门: HTML 定义了网页的内容 CSS 描述了网页的布局 JavaScript 网页的 ...