C# 数字转换成大写

 1 /// <summary>
 2         /// 数字转大写
 3         /// </summary>
 4         /// <param name="type">单价/数量</param>
 5         /// <param name="Num">数字</param>
 6         /// <returns></returns>
 7         public static string GetChineseNum(string type,string Num)
 8         {
 9             #region
10             try
11             {
12                 string m_1, m_2, m_3, m_4, m_5, m_6, m_7, m_8, m_9;
13                 m_1 = Num;
14                 string numNum = "0123456789.";
15                 string numChina = "零壹贰叁肆伍陆柒捌玖点";
16                 string numChinaWeigh = "个拾佰仟万拾佰仟亿拾佰仟万";
17                 if (Num.Substring(0, 1) == "0")//0123-->123
18                     Num = Num.Substring(1, Num.Length-1);
19                 if (!Num.Contains(‘.‘))
20                     Num += ".00";
21                 else//123.234  123.23 123.2
22                     Num = Num.Substring(0, Num.IndexOf(‘.‘) + 1 + (Num.Split(‘.‘)[1].Length > 2 ? 3 : Num.Split(‘.‘)[1].Length));
23                 m_1 = Num;
24                 m_2 = m_1;
25                 m_3 = m_4 = "";
26                 //m_2:1234-> 壹贰叁肆
27                 for (int i = 0; i < 11; i++)
28                 {
29                     m_2 = m_2.Replace(numNum.Substring(i, 1), numChina.Substring(i, 1));
30                 }
31                 //m_3:佰拾万仟佰拾个
32                 int iLen = m_1.Length;
33                 if (m_1.IndexOf(‘.‘) > 0)
34                     iLen = m_1.IndexOf(‘.‘);//获取整数位数
35                 for (int j = iLen; j >= 1; j--)
36                     m_3 += numChinaWeigh.Substring(j - 1, 1);
37                 //m_4:2行+3行
38                 for (int i = 0; i < m_3.Length; i++)
39                     m_4 += m_2.Substring(i, 1) + m_3.Substring(i, 1);
40                 //m_5:4行去"0"后拾佰仟
41                 m_5 = m_4;
42                 m_5 = m_5.Replace("零拾", "零");
43                 m_5 = m_5.Replace("零佰", "零");
44                 m_5 = m_5.Replace("零仟", "零");
45                 //m_6:00-> 0,000-> 0
46                 m_6 = m_5;
47                 for (int i = 0; i < iLen; i++)
48                     m_6 = m_6.Replace("零零", "零");
49                 //m_7:6行去亿,万,个位"0"
50                 m_7 = m_6;
51                 m_7 = m_7.Replace("亿零万零", "亿零");
52                 m_7 = m_7.Replace("亿零万", "亿零");
53                 m_7 = m_7.Replace("零亿", "亿");
54                 m_7 = m_7.Replace("零万", "万");
55                 if (m_7.Length > 2)
56                     m_7 = m_7.Replace("零个", "个");
57                 //m_8:7行+2行小数-> 数目
58                 m_8 = m_7;
59                 m_8 = m_8.Replace("个", "");
60                 if (m_2.Substring(m_2.Length - 3, 3) != "点零零")
61                     m_8 += m_2.Substring(m_2.Length - 3, 3);
62                 //m_9:7行+2行小数-> 价格
63                 m_9 = m_7;
64                 m_9 = m_9.Replace("个", "圆");
65                 if (m_2.Substring(m_2.Length - 3, 3) != "点零零")
66                 {
67                     m_9 += m_2.Substring(m_2.Length - 2, 2);
68                     m_9 = m_9.Insert(m_9.Length - 1, "角");
69                     m_9 += "分";
70                 }
71                 else m_9 += "整";
72                 if (m_9 != "零圆整")
73                     m_9 = m_9.Replace("零圆", "");
74                 m_9 = m_9.Replace("零分", "整");
75                 if (type == "数量")
76                     return m_8;
77                 else
78                     return m_9;
79             }
80             catch (Exception ex)
81             {
82                 return ex.Message;
83             }
84             #endregion
85         }
时间: 2024-10-25 07:37:24

C# 数字转换成大写的相关文章

PHP实现金额数字转换成大写函数

<?php header("Content-Type:text/html;charset=utf-8"); function num_to_upper($num) { $d = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖'); $e = array('元','拾','佰','仟','万','拾万','佰万','仟万','亿','拾亿','佰亿','仟亿','万亿'); $p = array('分','角'); $zheng='整';

js将数字转换成大写的人民币表达式

function changeNumMoneyToChinese(money) { var cnNums = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); //汉字的数字 var cnIntRadice = new Array(&qu

金额转换成大写

package com.liany.demo.translate; import java.math.BigDecimal; /** * @Description: 金额转换成大写 * @author huangzjb [email protected] * @Company Digital China * @date 2015-1-29 下午07:48:02 * @version 1.0 */ public class TransformMoney { /* 以下摘自百度百科:http://b

js 将数字转换成人民币大写的方法

//将数字转换成人民币大写的方法 var digitUppercase = function (n) { var fraction = ['角', '分']; var digit = [ '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' ]; var unit = [ ['元', '万', '亿'], ['', '拾', '佰', '仟'] ]; var IsNum = Number(n); if (!isNaN(IsNum)) { var hea

oracle数据库使用游标实现大写数字转换成小写数字

项目遇到需求,需要将大写数字转换成小写.代码如下: declare t_zl varchar2(100); t_ts varchar2(100); t_l number; hh varchar2(100); xx varchar2(100); type TIArray is table of varchar2(100);  type TCArray is table of varchar2(100); A TIArray;  B TCArray; cursor c is select zl,ts

数字转换成中文大小写、金额大小写

将数字转换成中文大小写.金额大小写  /// <summary> /// 将数字转换成中文大写 /// </summary> /// <param name="Value">数字</param> /// <param name="bToUpper">是否转换成汉字大写 true表示大写 false表示小写</param> /// <param name="bMoney"

老男孩教育每日一题-2017年5月4日-有一个oldboy.txt文件,把里面所有字母都转换成大写

老男孩教育每日一题-2017年5月4日-有一个oldboy.txt文件,把里面所有字母都转换成大写 文件内容如下: [[email protected] oldboy]# cat oldboy.txt  oldboy.blog.51cto.com www.oldboyedu.com 方法一:sed [[email protected] oldboy]# sed 's#[a-z]#\u&#g' oldboy.txt OLDBOY.BLOG.51CTO.COM WWW.OLDBOYEDU.COM 方

将金额转换成大写表示

function cny($ns) { static $cnums=array("零","壹","贰","叁","肆","伍","陆","柒","捌","玖"), $grees=array("圆","拾","佰","仟",&quo

android 设置字体颜色、EditText自动输入转换成大写字母的多种方式

在TextView上面设置某一个字的字体颜色为指定颜色时,可以通过java类SpannableString类和Html语言来实现. (一)SpannableString类方式 private void setText(TextView t){ String text = t.getText().toString().trim(); SpannableString span = new SpannableString(text); span.setSpan(new ForegroundColorS