C#金额小写转换为大写

//传入需要转换的金额(字符串)

public static string MoneyToChinese(string strAmount)     {

string functionReturnValue = null;

bool IsNegative = false; // 是否是负数

if (strAmount.Trim().Substring(0, 1) == "-")         {

// 是负数则先转为正数

strAmount = strAmount.Trim().Remove(0, 1);

IsNegative = true;

}

string strLower = null;

string strUpart = null;

string strUpper = null;

int iTemp = 0;

// 保留两位小数123.489→123.49  123.4→123.4

strAmount = Math.Round(double.Parse(strAmount), 2).ToString();

if (strAmount.IndexOf(".") > 0)         {

if (strAmount.IndexOf(".") == strAmount.Length - 2)             {

strAmount = strAmount + "0";

}

}

else         {

strAmount = strAmount + ".00";

}

strLower = strAmount;

iTemp = 1;

strUpper = "";

while (iTemp <= strLower.Length)         {

switch (strLower.Substring(strLower.Length - iTemp, 1))             {

case ".":

strUpart = "圆";

break;

case "0":

strUpart = "零";

break;

case "1":

strUpart = "壹";

break;

case "2":

strUpart = "贰";

break;

case "3":

strUpart = "叁";

break;

case "4":

strUpart = "肆";

break;

case "5":

strUpart = "伍";

break;

case "6":

strUpart = "陆";

break;

case "7":

strUpart = "柒";

break;

case "8":

strUpart = "捌";

break;

case "9":

strUpart = "玖";

break;

}

switch (iTemp)             {

case 1:

strUpart = strUpart + "分";

break;

case 2:

strUpart = strUpart + "角";

break;

case 3:

strUpart = strUpart + "";

break;

case 4:

strUpart = strUpart + "";

break;

case 5:

strUpart = strUpart + "拾";

break;

case 6:

strUpart = strUpart + "佰";

break;

case 7:

strUpart = strUpart + "仟";

break;

case 8:

strUpart = strUpart + "万";

break;

case 9:

strUpart = strUpart + "拾";

break;

case 10:

strUpart = strUpart + "佰";

break;

case 11:

strUpart = strUpart + "仟";

break;

case 12:

strUpart = strUpart + "亿";

break;

case 13:

strUpart = strUpart + "拾";

break;

case 14:

strUpart = strUpart + "佰";

break;

case 15:

strUpart = strUpart + "仟";

break;

case 16:

strUpart = strUpart + "万";

break;

default:

strUpart = strUpart + "";

break;

}

strUpper = strUpart + strUpper;

iTemp = iTemp + 1;

}

strUpper = strUpper.Replace("零拾", "零");

strUpper = strUpper.Replace("零佰", "零");

strUpper = strUpper.Replace("零仟", "零");

strUpper = strUpper.Replace("零零零", "零");

strUpper = strUpper.Replace("零零", "零");

strUpper = strUpper.Replace("零角零分", "整");

strUpper = strUpper.Replace("零分", "整");

strUpper = strUpper.Replace("零角", "零");

strUpper = strUpper.Replace("零亿零万零圆", "亿圆");

strUpper = strUpper.Replace("亿零万零圆", "亿圆");

strUpper = strUpper.Replace("零亿零万", "亿");

strUpper = strUpper.Replace("零万零圆", "万圆");

strUpper = strUpper.Replace("零亿", "亿");

strUpper = strUpper.Replace("零万", "万");

strUpper = strUpper.Replace("零圆", "圆");

strUpper = strUpper.Replace("零零", "零");

// 对壹圆以下的金额的处理

if (strUpper.Substring(0, 1) == "圆")         {

strUpper = strUpper.Substring(1, strUpper.Length - 1);

}

if (strUpper.Substring(0, 1) == "零")         {

strUpper = strUpper.Substring(1, strUpper.Length - 1);

}

if (strUpper.Substring(0, 1) == "角")         {

strUpper = strUpper.Substring(1, strUpper.Length - 1);

}

if (strUpper.Substring(0, 1) == "分")         {

strUpper = strUpper.Substring(1, strUpper.Length - 1);

}

if (strUpper.Substring(0, 1) == "整")         {

strUpper = "零圆整";

}

functionReturnValue = strUpper;

if (IsNegative == true)         {

return "负" + functionReturnValue;

}

else         {

return functionReturnValue;

}

}

时间: 2024-10-10 07:20:46

C#金额小写转换为大写的相关文章

js 金额小写转换为大写

<script> jQuery(document).ready(function () { //当金额文本框失去焦点时,自动将数字转化为大写填充到 大写的文本框中 $("#Amount").blur(function () { var amount = $("#Amount").val(); amount = AmountLtoU(amount); $("#CapitalAmount").val(amount); }); }); fu

JS函数实现金额小写转大写

止乎于分享! 1 ///<summery>小写金额转化大写金额</summery> 2 function AmountLtoU(amount) { 3 if (isNaN(amount) || amount >= 1000000000000) return "无效金额!"; //数值最大不超过1万亿 4 var sPrefix = amount < 0 ? "(负)" : ""; //将负号‘-’显示成汉字‘(

将金额数字转换为大写汉字的js函数

1 //将金额数字转换为大写汉字的函数 2 function convertCurrency(money) { 3 //汉字的数字 4 var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'); 5 //基本单位 6 var cnIntRadice = new Array('', '拾', '佰', '仟'); 7 //对应整数部分扩展单位 8 var cnIntUnits = new Array('', '

传入一个字符串,已知字符串只由字母组成,将其中的大写字母转换为小写,小写转换为大写,返回转换后的字符串

传入一个字符串,已知字符串只由字母组成,将其中的大写字母转换为小写,小写转换为大写,返回转换后的字符串 如传入:@"GOODgoodSTUDY",返回@"goodGOODstudy" */ - (NSString *)upperExchangeLower:(NSString *)str { NSMutableString *str1=[[NSMutableString alloc] initWithString:str]; for (NSUInteger i=0;

[转] 金额小写变大写

1 /// <summary> 2 /// 金额小写变大写 3 /// </summary> 4 /// <param name="smallnum"></param> 5 /// <returns></returns> 6 public static string gMoney(decimal smallnum) 7 { 8 string cmoney , cnumber, cnum, cnum_end,cmon

C#金额小写转大写

public string ConvertMoney(decimal Money) { //金额转换程序 string MoneyNum = "";//记录小写金额字符串[输入参数] string MoneyStr = "";//记录大写金额字符串[输出参数] string BNumStr = "零壹贰叁肆伍陆柒捌玖";//模 string UnitStr = "万仟佰拾亿仟佰拾万仟佰拾圆角分";//模 MoneyNum =

SQL金额小写转大写

CREATE FUNCTION dbo.L2U(@n_LowerMoney numeric(15,2),@v_TransType int) RETURNS VARCHAR(200) AS BEGIN Declare @v_LowerStr VARCHAR(200) -- 小写金额 Declare @v_UpperPart VARCHAR(200) Declare @v_UpperStr VARCHAR(200) -- 大写金额 Declare @i_I int set @v_LowerStr =

Java中金额数字转换为大写数字

注:该代码来自于别人,我引入进来并修改了里面的几个bug.现在写进我的博客里,以便于日后查看,和为其它博友们提供方便 修改bug地方:1.金额为0时,不加整.以前是零元整,现在是零元    2.修改"分", "角", "元","万", "亿","兆"位不会出现零 package com.zbx.bs.common.util;import java.math.BigDecimal; /**

Python TIPS上一道关于人民币金额小写转大写的题

人民币金额打印 题目链接:here.我发现我写的好复杂,但万幸编码还算符合人类,看了其他答案,感觉都是天书. #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2017-06-09 # @Author : Bob Liao ([email protected]) # @Link : https://github.com/coderchaser # @Version : python3.4 #创建大小写转换字典 num_dic={ #