金额大小写转换宏编程
大小写金额转换
*大小写金额转换DA TA: L_DXSTR(60). "大写金额DA TA: HJ_JFJE LIKE BSEG-WRBTR. "小写金额HJ_JFJE = '234687.88'.PERFORM XX_CHANGE_DX USING HJ_JFJE CHANGING L_DXSTR.*FORM XX_CHANGE_DX using valchanging dxstr.DA TA: ZS(15).DA TA: XS(15).DA TA: STR(15).DA TA: LEN TYPE I V ALUE 0.DA TA: CIS TYPE I V ALUE 0.DA TA: SS(2).DA TA: RR(1).DA TA: STRR(15).DA TA: change(30) TYPE C V ALUE '1壹2贰3叁4肆5伍6陆7柒8捌9玖0零'.CLEAR DXSTR.MOVE V AL TO STR.SHIFT STR LEFT DELETING LEADING SPACE.SPLIT STR A T '.' INTO ZS XS.LEN = STRLEN( ZS ).CLEAR STRR.CIS = LEN - 1.DO LEN TIMES.MOVE ZS+CIS(1) TO RR.CONCA TENA TE STRR RR INTO STRR.CIS = CIS - 1.ENDDO.CIS = 0.DO LEN TIMES.MOVE STRR+CIS(1) TO SS.TRANSLA TE SS USING change.CASE CIS.WHEN 0. CONCA TENA TE SS '元' INTO DXSTR.WHEN 1. CONCA TENA TE SS '拾' DXSTR INTO DXSTR.WHEN 2. CONCA TENA TE SS '佰' DXSTR INTO DXSTR.WHEN 3. CONCA TENA TE SS '仟' DXSTR INTO DXSTR.WHEN 4. CONCA TENA TE SS '万' DXSTR INTO DXSTR.WHEN 5. CONCA TENA TE SS '拾' DXSTR INTO DXSTR.WHEN 6. CONCA TENA TE SS '佰' DXSTR INTO DXSTR.WHEN 7. CONCA TENA TE SS '仟' DXSTR INTO DXSTR.WHEN 8. CONCA TENA TE SS '亿' DXSTR INTO DXSTR.WHEN 9. CONCA TENA TE SS '拾' DXSTR INTO DXSTR.WHEN 10. CONCA TENA TE SS '百' DXSTR INTO DXSTR.WHEN 11. CONCA TENA TE SS '仟' DXSTR INTO DXSTR.ENDCASE.CIS = CIS + 1.ENDDO.CLEAR SS.IF XS <> '00'.MOVE XS+0(1) TO SS. TRANSLA TE SS USING change.CONCA TENA TE DXSTR SS '角' INTO DXSTR.MOVE XS+1(1) TO SS. TRANSLA TE SS USING change.CONCA TENA TE DXSTR SS '分' INTO DXSTR.ENDIF.CONCA TENA TE DXSTR '整' INTO DXSTR.ENDFORM. " XX_CHANGE_DX我的程序写的比较粗糙,转换方法比较笨。
银行小写金额转成大写金额的java方法
Java将数字金额转换成中文大写形式import java.math.BigDecimal;import java.math.RoundingMode;public class ChineseMoneyUtils {/*** 中文数字*/final static private String[] CHINESE_NUMBER = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };/*** 中文数字单位*/final static private String[] CHINESE_NUMBER_UNIT = { "", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟" };/*** 人民币单位*/final static private String[] CHINESE_MONEY_UNIT = { "圆", "角", "分" };public static void main(String[] args) {String chineseMoney = toChineseMoney(new BigDecimal("320"));System.out.println("chineseMoney = " + chineseMoney);}/*** @param sourceMoney 要转换的数值,最多支持到亿* @return 结果*/public static String toChineseMoney(BigDecimal sourceMoney) {if (new BigDecimal("1000000000000").compareTo(sourceMoney) <= 0&& pareTo(sourceMoney) >= 0) {throw new RuntimeException("支持转换的金额范围为0~1万亿");}StringBuilder sb = new StringBuilder();// 整数部分BigDecimal intPart = sourceMoney.setScale(0, RoundingMode.DOWN);// 小数部分BigDecimal decimalPart = sourceMoney.subtract(intPart).multiply(newBigDecimal(100)).setScale(0,RoundingMode.DOWN);// 处理整数部分圆if (pareTo(BigDecimal.ZERO) > 0) {String intPartNumberString = intPart.toPlainString();int length = intPartNumberString.length();// 统计末尾的零,末尾零不做处理int zeroCount = 0;for (int i = length - 1; i >= 0; i--) {int number = Integer.parseInt(String.valueOf(intPartNumberString.charAt(i)));if (number == 0) {zeroCount++;} else {break;}}for (int i = 0; i < length; i++) {// 如果转换到末尾0,则停止转换if (i + zeroCount == length) {break;}int number = Integer.parseInt(String.valueOf(intPartNumberString.charAt(i)));// 获取中文数字String chineseNumber = CHINESE_NUMBER[number];// 获取中文数字单位String chineseNumberUnit = CHINESE_NUMBER_UNIT[length - i - 1];sb.append(chineseNumber).append(chineseNumberUnit);}// 统计完后加上金额单位sb.append(CHINESE_MONEY_UNIT[0]);} else {sb.append(CHINESE_NUMBER[0]).append(CHINESE_MONEY_UNIT[0]);}// 处理小数部分if (pareTo(new BigDecimal(10)) >= 0) {// 角String jiao = decimalPart.toPlainString();int number = Integer.parseInt(String.valueOf(jiao.charAt(0)));if (number != 0) {String chineseNumber = CHINESE_NUMBER[number];sb.append(chineseNumber).append(CHINESE_MONEY_UNIT[1]);}// 分String fen = decimalPart.toPlainString();number = Integer.parseInt(String.valueOf(fen.charAt(1)));if (number != 0) {String chineseNumber = CHINESE_NUMBER[number];sb.append(chineseNumber).append(CHINESE_MONEY_UNIT[2]);}} else if (pareTo(BigDecimal.ZERO) > 0) {// 分String fen = decimalPart.toPlainString();int number = Integer.parseInt(String.valueOf(fen.charAt(0)));if (number != 0) {String chineseNumber = CHINESE_NUMBER[number];sb.append(chineseNumber).append(CHINESE_MONEY_UNIT[2]);}} else {sb.append("整");}return sb.toString();}}。
人民币大写转换函数
人民币大写转换函数Function N2RMB(M)y = Int(Round(100 * Abs(M)) / 100)j = Round(100 * Abs(M) + 0.00001) - y * 100f = (j / 10 - Int(j / 10)) * 10A = IIf(y < 1, "", Application.Text(y, "[DBNum2]") & "元")b = IIf(j > 9.5, Application.Text(Int(j / 10), "[DBNum2]") & "角", IIf(y < 1, "", IIf(f > 1, "零", "")))c = IIf(f < 1, "整", Application.Text(Round(f, 0), "[DBNum2]") & "分")N2RMB = IIf(Abs(M) < 0.005, "", IIf(M < 0, "负" & A & b & c, A & b & c))End Function另外一个函数:Function dx(M) '一条语句163个字符dx = Replace(Replace(Replace(Join(Application.Text(Split(Format(M, "0. 0 0;负 0. 0 0; ")), ["[DBnum2]"&{0,"","元0角;;元零","0分;;整"}]),a), "零元零", a), "零元", a), "零整", "整")End Function代码解析:代码中使用了Replace()、Join()、Split()、Format()等4个VBA 函数,以及1个工作表函数T ext()。
Excel-VBA自定义函数将人民币数字转换为大写
Excel-VBA自定义函数将人民币数字转换为大写应用场景财务报表中将人民币数字转换为大写知识要点1:Round(单元格, 2)返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果2:Range.Text 属性返回或设置指定对象中的文本。
String 型,只读3:[DBnum2] 格式函数, 数字转中文大写Function 大写(单元格 As String) As StringApplication.VolatileDim Bum, rmbsIf Len(单元格) = 0 Then 大写 = ''If 单元格 = 0 Then 大写 = '零元整': Exit Functionrmbs = Replace(Replace(Application.Text(Round(单元格, 2), '[DBnum2]'), '.', '元'), '-', '负')rmbs = IIf(Left(Right(rmbs, 3), 1) = '元', Left(rmbs, Len(rmbs) - 1) & '角' & Right(rmbs, 1) & '分', IIf(Left(Right(rmbs, 2), 1) = '元', rmbs & '角', IIf(rmbs = '零', '', rmbs & '元整')))rmbs = Replace(Replace(rmbs, '零元', ''), '零角', '') '将零元零角转换为空文本大写 = rmbsEnd Function。
excel表格中数字自动变成人民币大写的函数
标题:excel表格中数字自动变成人民币大写的函数在许多日常工作中,我们经常会用到Microsoft Excel这一办公软件来处理数据和表格。
在处理涉及人民币金额的时候,通常需要将数字自动转换成人民币大写的形式,这不仅方便了数据的阅读和理解,也符合财务报表的要求。
下面介绍一种在Excel中实现这一功能的方法,希望对大家有所帮助。
1. 准备工作在使用Excel表格处理人民币金额时,首先需要保证表格中含有人民币金额的数字列。
假设我们要将A列的数字自动转换成人民币大写,我们可以将转换后的结果显示在B列。
2. 编写函数在B列的第一个单元格中,输入以下函数来实现将数字自动转换成人民币大写的功能:=人民币(A1)其中,A1代表了要转换的人民币金额所在的单元格,人民币()为自定义的转换函数名称,可以根据个人喜好进行修改。
3. 自定义函数在Excel中,默认并没有内置的函数来实现将数字转换成人民币大写的功能,因此需要通过自定义宏来实现。
以下是一个示例的自定义函数,供大家参考:Function 人民币(ByVal MyNumber) As StringDim Dollars, Cents, TempDim DecimalPlace, CountReDim place(9) As Stringplace(2) = " Thousand "place(3) = " Million "place(4) = " Billion "place(5) = " Trillion "' String representation of amount.MyNumber = Trim(Str(MyNumber))' Position of decimal place 0 if none.DecimalPlace = InStr(MyNumber, ".")' Convert cents and set MyNumber to dollar amount.If DecimalPlace > 0 ThenCents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) _ "00", 2))MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))End IfCount = 1Do While MyNumber <> ""Temp = GetHundreds(Right(MyNumber, 3))If Temp <> "" Then Dollars = Temp place(Count) Dollars If Len(MyNumber) > 3 ThenMyNumber = Left(MyNumber, Len(MyNumber) - 3)ElseMyNumber = ""End IfCount = Count + 1LoopSelect Case DollarsCase ""Dollars = "No Dollars"Case "One"Dollars = "One Dollar"Case ElseDollars = Dollars " 元"End SelectSelect Case CentsCase ""Cents = " and No Cents"Case "One"Cents = " and One Cent"Case ElseCents = " and " Cents " 分"End Select人民币 = Dollars CentsEnd FunctionFunction GetHundreds(ByVal MyNumber)Dim Result As StringIf Val(MyNumber) = 0 Then Exit FunctionMyNumber = Right("000" MyNumber, 3)If Mid(MyNumber, 1, 1) <> "0" ThenResult = GetDigit(Mid(MyNumber, 1, 1)) " 百"End IfIf Mid(MyNumber, 2, 1) <> "0" ThenResult = Result GetDigit(Mid(MyNumber, 2, 1)) " 十"ElseIf Mid(MyNumber, 1, 1) <> "0" And Mid(MyNumber, 2, 1) = "0" ThenResult = Result " 零"End IfEnd IfIf Mid(MyNumber, 3, 1) <> "0" ThenResult = Result GetDigit(Mid(MyNumber, 3, 1))End IfGetHundreds = ResultEnd FunctionFunction GetTens(TensText)Dim Result As StringResult = "" ' Null out the temporary function value. If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19... Select Case Val(TensText)Case 10: Result = "十"Case 11: Result = "十一"Case 12: Result = "十二"Case 13: Result = "十三"Case 14: Result = "十四"Case 15: Result = "十五"Case 16: Result = "十六"Case 17: Result = "十七"Case 18: Result = "十八"Case 19: Result = "十九"Case ElseEnd SelectElse ' If value between 20-99...Select Case Val(Left(TensText, 1))Case 2: Result = "二十 "Case 3: Result = "三十 "Case 4: Result = "四十 "Case 5: Result = "五十 "Case 6: Result = "六十 "Case 7: Result = "七十 "Case 8: Result = "八十 "Case 9: Result = "九十 "Case ElseEnd SelectResult = Result GetDigit _(Right(TensText, 1)) ' Retrieve ones place. End IfGetTens = ResultEnd FunctionFunction GetDigit(Digit)Select Case Val(Digit)Case 1: GetDigit = "一"Case 2: GetDigit = "二"Case 3: GetDigit = "三"Case 4: GetDigit = "四"Case 5: GetDigit = "五"Case 6: GetDigit = "六"Case 7: GetDigit = "七"Case 8: GetDigit = "八"Case 9: GetDigit = "九"Case Else: GetDigit = ""End SelectEnd Function4. 使用自定义函数在完成自定义函数的编写后,我们可以在B列的第一个单元格中输入=人民币(A1),然后按下Enter键,即可看到A1单元格中的人民币金额被自动转换成人民币大写的形式,并显示在B1单元格中。
excel金额大写自动生成的公式
一、介绍Excel金额大写自动生成的公式在日常工作中,我们经常会遇到需要将阿拉伯数字金额转换为大写金额的情况。
而在Excel中,我们可以利用公式来实现这一转换,从而提高工作效率。
本文将介绍Excel中金额大写自动生成的公式的使用方法和注意事项。
二、公式的基本原理1. 在Excel中,可以利用VBA编程语言来编写宏以实现金额大写自动生成的功能。
通过编写相应的VBA代码,可以使Excel自动将输入的数字金额转换为大写金额。
2. 公式的基本原理是将输入的阿拉伯数字金额拆分成整数和小数部分,然后分别进行转换为大写金额,最后将整数和小数部分的大写金额合并为最终结果。
三、公式的具体实现步骤1. 在Excel中,首先需要按下Alt + F11组合键打开VBA编辑器,在项目资源管理器中选择需要添加宏的工作簿。
2. 在选中的工作簿中插入一个新的模块,然后在模块中编写相应的VBA代码。
可以借助搜索引擎查找金额大写自动生成的VBA代码,然后将其粘贴到模块中。
3. 在编写完成VBA代码后,可以利用快捷键Alt + F8来运行宏,或者将宏添加到快速访问工具栏,方便日常使用。
四、注意事项1. 在使用金额大写自动生成的公式时,需要确保输入的金额格式正确,且没有特殊符号和字母等非数字字符。
2. 由于VBA代码的复杂性和灵活性,建议在使用前充分了解其功能和运行原理,以避免出现不必要的错误和问题。
3. 在日常工作中,需要根据具体的需求,对金额大写自动生成的公式进行必要的修改和调整,以满足不同的应用场景。
五、结语通过以上介绍,相信大家对Excel金额大写自动生成的公式有了一定的了解。
在实际工作中,合理利用Excel的功能和公式,可以提高工作效率,减少重复劳动,帮助我们更好地处理各类金额转换的需求。
希望本文的介绍能够对大家有所帮助。
六、如何修改VBA代码以适应不同的需求1. 调整显示格式:根据实际需求,我们可以修改VBA代码中的显示格式,包括小数点后保留位数、显示大写金额的格式等。
EXCEL金额大小写转换公式大全
EXCEL金额大小写转换公式大全在Excel中,我们可以使用宏或函数来实现金额大小写转换。
下面是一些常用的方法和公式:1.宏:可根据需要编写一个VBA宏来实现金额大小写转换。
以下是一个示例宏代码:```vbaOption ExplicitFunction ConvertNumberToWords(ByVal MyNumber)Dim DecimalPlace, CountReDim Place(9) As StringPlace(2) = " Thousand "Place(3) = " Million "Place(4) = " Billion "Place(5) = " Trillion "MyNumber = Trim(CStr(MyNumber))MyNumber = Replace(MyNumber, ",", "")DecimalPlace = InStr(MyNumber, ".")Count = 1Do While DecimalPlace <> 0If Count = 1 ThenMyNumber = Left(MyNumber, DecimalPlace - 1) &GetTens(Mid(MyNumber, DecimalPlace + 1) & "00")End IfIf Count = 2 Then MyNumber = Left(MyNumber, DecimalPlace - 1) & GetTens(Mid(MyNumber, DecimalPlace + 1) & "00") & " Cents"DecimalPlace = 0Count = Count + 1LoopSelect Case CountCase 1MyNumber = MyNumber & " Only"Case 2MyNumber = MyNumberEnd SelectConvertNumberToWords = Trim(MyNumber)End FunctionFunction GetDigit(ByVal Digit)Select Case Val(Digit)Case 1: GetDigit = "One"Case 2: GetDigit = "Two"Case 3: GetDigit = "Three"Case 4: GetDigit = "Four"Case 5: GetDigit = "Five"Case 6: GetDigit = "Six"Case 7: GetDigit = "Seven"Case 8: GetDigit = "Eight"Case 9: GetDigit = "Nine"Case Else: GetDigit = ""End SelectEnd FunctionFunction GetTens(TensText)Dim Quantity As StringQuantity = ""If Val(Left(TensText, 1)) = 1 Then Select Case Val(TensText)Case 10: Quantity = "Ten"Case 11: Quantity = "Eleven"Case 13: Quantity = "Thirteen" Case 14: Quantity = "Fourteen" Case 15: Quantity = "Fifteen" Case 16: Quantity = "Sixteen" Case 17: Quantity = "Seventeen" Case 18: Quantity = "Eighteen" Case 19: Quantity = "Nineteen" Case ElseEnd SelectElseSelect Case Val(Left(TensText, 1)) Case 2: Quantity = "Twenty "Case 3: Quantity = "Thirty "Case 4: Quantity = "Forty "Case 5: Quantity = "Fifty "Case 6: Quantity = "Sixty "Case 7: Quantity = "Seventy " Case 8: Quantity = "Eighty "Case ElseEnd SelectQuantity = Quantity & GetDigit(Right(TensText, 1))End IfGetTens = QuantityEnd Function```在“开发工具”选项卡下的宏对话框中,输入上述代码,并保存。
人民币大小写转换(C#)
⼈民币⼤⼩写转换(C#)今天写了⼀个C#版本的⼤⼩写转换类,想着也要更新⼀下我的⽇记了,便把它传了上来。
哪位路过的⾼⼿,请指点。
这个类提供了⼀个静态⽅法叫做 Convert ( double ),传⼊⼀个9千万亿以内的数值它都能正确的转换为中⽂的⼤写。
基本的思路是将传⼊的数据分为整数部分和⼩数部分分别来处理,⼩数部分的处理⽐较简单,整数部分的处理我作了相应的注释。
1using System;23namespace Tools{4///<summary>5/// DigitalToChinese :实现将⼈民币的数字形式转换为中⽂格式。
6///</summary>7public class DigitalToChinese8 {9public DigitalToChinese(){10 }1112public static string Convert ( double digital ){13if ( digital == 0.00f )14return "零元整";1516string buf = ""; /* 存放返回结果 */17string strDecPart = ""; /* 存放⼩数部分的处理结果 */18string strIntPart = ""; /* 存放整数部分的处理结果 */1920/* 将数据分为整数和⼩数部分 */21char [] cDelim = {'.'};22string [] tmp = null;23string strDigital = digital.ToString ();24if ( strDigital[0] =='.'){ /* 处理数据⾸位为⼩数点的情况 */25 strDigital = "0" + strDigital;26 }27 tmp = strDigital.Split ( cDelim,2);2829/* 整数部分的处理 */30if ( tmp[0].Length > 15 ) {31throw new Exception ("数值超出处理范围。
金额小写转大写 Borland C++ Bulider 6.0 BCB 源代码 Source Code
if (i==0) XiaoXieStr=s+"00"; //如果是整数,没有小数点补两位角分, 缺陷如是有3位小数出错
else if (i==s.Length()) XiaoXieStr=s+"00";
else if (i==s.Length()-1) XiaoXieStr=s+"0";
MidDX.Delete(1,2); //如果第一位是元, 去掉比如0.01,0.11
if ((MidDX.SubString(1,2)=="零") )
MidDX.Delete(1,2); //如果第一位是零, 去掉 比如0.01
if ((MidDX.SubString(MidDX.Length()-3,4)=="元零") )
{MidDX=MidDX.SubString(1,MidDX.Length()-2)+"整";
return MidDX; }
if ((MidDX.SubString(MidDX.Length()-3,4)=="角零" ))
//阿拉伯金额数字元位是“0”,或数字中间连续有几个“0”,元位也是“0”,但角位不是“0”时,汉字大写金额可只写一个“零”字,也可不写“零”字,
//如¥1,320.56,汉字大写金额应写成人民币壹仟叁佰贰拾圆零伍角陆分,或人民币壹仟叁佰贰拾圆伍角陆分。
//又如¥1,000.56,汉字大写金额应写成人民币壹仟圆零伍角陆分,或人民币壹仟圆伍角陆分。
if (MidDX.SubString(oi,4)=="零零" )
中文金额大小写转换公式模板
中文金额大小写转换公式模板```#定义数字字符对应的中文大写字符digits = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']#定义单位字符对应的中文大写字符units = ['', '拾', '佰', '仟', '万', '亿']#将阿拉伯数字表示的金额转换为中文表示的金额def convert_amount_to_chinese(amount):#将金额转换为字符串amount_str = str(amount)#判断金额是否合法if not amount_str.isdigit(:return '金额不合法'#去除金额首部的零amount_str = amount_str.lstrip('0')#如果金额为0,直接返回“零元整”if amount_str == '0':return '零元整'#分割金额的整数部分和小数部分integer_part, decimal_part = amount_str.split('.') #转换整数部分的金额chinese_amount =convert_integer_part_to_chinese(integer_part) + '元' #当小数部分为00时,添加“整”if decimal_part == '00':chinese_amount += '整'else:#转换小数部分的金额chinese_amount +=convert_decimal_part_to_chinese(decimal_part) return chinese_amount#将整数部分的金额转换为中文表示def convert_integer_part_to_chinese(integer_part): #反转整数部分字符串,便于从低位到高位处理integer_part = integer_part[::-1]#初始化中文表示的整数部分金额字符串chinese_amount = ''#判断整数部分是否为零if integer_part == '0':return '零'#迭代处理整数部分的每一位for i, digit in enumerate(integer_part):#当前数字为零时,如果下一位数字也为零,则跳过if digit == '0' and i + 1 < len(integer_part) andinteger_part[i + 1] == '0':continue#获取当前数字的中文大写字符digit_char = digits[int(digit)]#获取当前数字的单位字符unit_char = units[i % 4]#如果当前数字为零且单位字符不为空,则在金额后添加单位字符if digit == '0' and unit_char != '':chinese_amount = digit_char + chinese_amount#如果当前数字不为零,则在金额后添加当前数字和单位字符elif digit != '0':chinese_amount = digit_char + unit_char + chinese_amount#如果当前数字不为零且单位字符不为空,则在金额后添加零if digit != '0' and unit_char != '':chinese_amount = digits[0] + chinese_amountreturn chinese_amount#将小数部分的金额转换为中文表示def convert_decimal_part_to_chinese(decimal_part):#获取小数部分的十位和个位数字ten_digit = decimal_part[0]one_digit = decimal_part[1]#初始化中文表示的小数部分金额字符串chinese_amount = ''#根据小数部分的十位和个位数字转换为中文表示if ten_digit != '0':chinese_amount += digits[int(ten_digit)] + '角'if one_digit != '0':chinese_amount += digits[int(one_digit)] + '分' return chinese_amount```请注意,该公式模板仅适用于转换人民币金额,不适用于其他货币单位。
Excel中金额大小写转换(解决负数无法显示问题)
Excel中金额大小写转换(解决负数无法显示问题)一、Excel自动转换数字大小写具体的操作步骤如下:1. 启动excel。
按“alt+f11”快捷键打开“visual basic编辑器”。
2. 在“visual basic编辑器”中,单击“插入”菜单栏中的“模块”命令,插入一个模块。
双击左侧“工程”窗口中的“模块1”选项,在窗口右边展开“模块1(代码)”编辑窗口,然后输入如下代码:Function NtoC(n) 'n as singleConstcNum = "零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分"ConstcCha = "零仟零佰零拾零零零零零亿零万零元亿万零角零分零整-零零零零零亿万元亿零整整"NtoC = ""sNum = Trim(Str(Int(n * 100)))For i = 1 To Len(sNum) '逐位转换NtoC = NtoC + Mid(cNum, (Mid(sNum, i, 1)) + 1, 1) + Mid(cNum, 26 - Len(sNum) + i, 1)NextFor i = 0 To 11 '去掉多余的零NtoC = Replace(NtoC, Mid(cCha, i * 2 + 1, 2), Mid(cCha, i + 26, 1))NextEnd Function3.练习A1=-10135.33 A2=NTOC(ABS(A1))二、Excel中金额大小写转换公式公式1:“=IF(ROUND(E19,2)=0,"",IF(ROUND(ABS(E19),2)>=1,TEXT(INT(ROUND(ABS(E19),2)),"[DBNum2]" )&"元","")&IF(RIGHT(TEXT(E19,".00"),2)*1=0,"整",IF(RIGHT(TEXT(E19,".00"),4)*1>=1,IF(RIGHT(TEXT(E19,".00"),2)*1>9,"","零"),IF(ROUND(ABS(E19),2)>=1,"零",""))&IF(RIGHT(TEXT(E19,".00"),2)*1>9,TEXT(LEFT(RIGHT(TEXT(E19,".00"),2)),"[DBNum2]")&"角","")&IF(RIGHT(TEXT(E19,".00"))*1>0,TEXT(RIGHT(TEXT(E19,".00")),"[DBNum2]")&"分","整")))”公式2:“=IF(F4<1,IF(F4<0.1,TEXT(INT(F4*100),"[DBNum2]G/通用格式")&"分",IF((INT(F4*100)-INT(F4*10)*10=0),TEXT(INT(F4*10),"[DBNum2]G/通用格式")&"角整",TEXT(INT(F4*10),"[DBNum2]G/通用格式")&"角"&TEXT(INT(F4*100)-INT(F4*10)*10,"[DBNum2]G/通用格式")&"分")),TEXT(INT(F4),"[DBNum2]G/通用格式"&"元")&IF((INT(F4*10)-INT(F4)*10)=0,IF((INT(F4*100)-INT(F4*10)*10)=0,"","零"),IF((INT(F4*0.1)-INT(F4)*0.1)=0,"零","")&TEXT(INT(F4*10)-INT(F4)*10,"[DBNum2]G/通用格式")&"角")&IF((INT(F4*100)-INT(F4*10)*10)=0,"整",TEXT(INT(F4*100)-INT(F4*10)*10,"[DBNum2]G/通用格式")&"分"))”公式3:“=IF(B10<1,IF(B10<0.1,TEXT(INT(B10*100),"[DBNum2]G/通用格式")&"分",IF((INT(B10*100)-INT(B10*10)*10=0),TEXT(INT(B10*10),"[DBNum2]G/通用格式")&"角整",TEXT(INT(B10*10),"[DBNum2]G/通用格式")&"角"&TEXT(INT(B10*100)-INT(B10*10)*10,"[DBNum2]G/通用格式")&"分")),TEXT(INT(B10),"[DBNum2]G/通用格式"&"元")&IF((INT(B10*10)-INT(B10)*10)=0,IF((INT(B10*100)-INT(B10*10)*10)=0,"","零"),IF((INT(B10*0.1)-INT(B10)*0.1)=0,"零","")&TEXT(INT(B10*10)-INT(B10)*10,"[DBNum2]G/通用格式")&"角")&IF((INT(B10*100)-INT(B10*10)*10)=0,"整",TEXT(INT(B10*100)-INT(B10*10)*10,"[DBNum2]G/通用格式")&"分"))”。
c++程序小写金额转化成大写金额
y1=y1/10;}/*取各位上的数字*/
for(n=0;;n++)
{
if(num[n]=0;j--)/*判断是否是万位,亿位..如是再判断是否是0如是就不输出零.*/
{
if(m<=5)
if(m==5&&(int)num[j]==0)
{
num[i]=(char)(n%10);
n/=10;
}
m=i;
num[i]='.';
for(y=y*10;(long)((y-(long)y)*10);) /*如果小数位还是有数(非0)循环继续*/
y*=10;/*小数转化为整数如0.11111转为11111.00...*/
y1=(long)y;
for(i=m+1;y1!=0;i++)
金额小写转大写小写转大写word小写变大写小写转换大写英文小写转大写大写变小写小写转大写公式小写换大写sql大写转小写java大写转小写
#include<stdio.h>
void main()
{
double x,y;
char *ch[]={"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"};
char *ch1[]={"拾","佰","仟","万","拾","佰","仟","亿"};
java不失精度及金额大小写转换
java不失精度及金额大小写转换1.不失精度的数据运算功能:在数据运算过程中将小数点后的数据无失真的进行运算,保证了数据的精确性。
实现方法:import java.math.BigDecimal;public class ArithUtil {//默认除法运算精度private static final int DEF_DIV_SCALE = 10;//这个类不能实例化private ArithUtil(){}/*** @方法名: add** @方法概要: 提供精确的加法运算** @param@param v1 被加数* @param@param v2 加数** @return double 两个参数的和** @date*/public static double add(double v1,double v2){BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));return b1.add(b2).doubleValue();}/*** @方法名: sub** @方法概要: 提供精确的减法运算** @param@param v1 被减数* @param@param v2 减数** @return double 两个参数的差** @throws抛出的异常** @date */public static double sub(double v1,double v2){ BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.subtract(b2).doubleValue();}/*** @方法名: mul** @方法概要: 提供精确的乘法运算** @param v1 被乘数* @param v2 乘数** @return double 两个参数的积** @throws** @date */public static double mul(double v1,double v2){BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));return b1.multiply(b2).doubleValue();}/*** @方法名: div** @方法概要: 提供(相对)精确的除法运算,当发生除不尽的情况时,精确的小数点以后10位* 以后的数字四舍五入* @param@param v1 被除数* @param@param v2 除数** @return double 两个参数的商** @throws** @date */public static double div(double v1,double v2){return div(v1,v2,DEF_DIV_SCALE);}/*** @方法名: div** @方法概要: 提供(相对)精确的除法运算* 当发生除不尽的情况时,由scale参数指定精度,以后的数字四舍五入* @param@param v1 被除数* @param@param v2 除数* @param@param scale 表示需要精确到小数点以后几位** @return double 两个参数的商** @throws** @date*/public static double div(double v1,double v2,int scale){ if(scale<0){throw new IllegalArgumentException("精确数必须是正整数或零");}BigDecimal b1 = new BigDecimal(Double.toString(v1));BigDecimal b2 = new BigDecimal(Double.toString(v2));returnb1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue(); } }2.数字金额转换功能:将小写的数字金额转换为票据数字public class ChangeCapNum {// 整数部分private static String integerPart;// 小数部分private static String floatPart;// 将数字转化为汉字的数组,因为各个实例都要使用所以设为静态private static final char[] cnNumbers={'零','壹','贰','叁','肆','伍','陆','柒','捌','玖'};// 供分级转化的数组,因为各个实例都要使用所以设为静态private static final char[] series={'元','拾','百','仟','万','拾','百','仟','亿'};/*** @方法名: dataInit** @方法概要:将阿拉伯数字形式的字符串传入*/private static void dataInit(String original){// 成员变量初始化integerPart="";floatPart="";if(original.contains(".")){// 如果包含小数点int dotIndex=original.indexOf("."); integerPart=original.substring(0,dotIndex); floatPart=original.substring(dotIndex+1);}else{// 不包含小数点integerPart=original;}}/*** @方法名: getCnString** @方法概要: 取得大写形式的字符串*/public static String getCnString(String original){ //将阿拉伯数字形式的字符串传入dataInit(original);// 因为是累加所以用StringBuffer StringBuffer sb=new StringBuffer();// 整数部分处理for(int i=0;i<integerpart.length();i++){< p=""> int number=getNumber(integerPart.charAt(i)); sb.append(cnNumbers[number]);sb.append(series[integerPart.length()-1-i]);}// 如果整数部分后面是零则去除for(int i=integerPart.length()-1;i>0;i--){if(integerPart.charAt(i)=='0'){sb.delete(sb.length()-2, sb.length());}else{sb.append("元");break;}}// 小数部分处理if(floatPart.length()>0){if(Integer.parseInt(floatPart)!=0){//去除"元"sb.deleteCharAt(sb.length()-1);sb.append("点");for(int i=0;i<floatpart.length();i++){< p=""> int number=getNumber(floatPart.charAt(i)); sb.append(cnNumbers[number]);}sb.append("元");}}//加"整"s b.append("整");// 返回拼接好的字符串return sb.toString();}/*** @方法名: getNumber** @方法概要: 将字符形式的数字转化为整形数字** @param c 要转化的数字*/private static int getNumber(char c){ String str=String.valueOf(c);return Integer.parseInt(str);}}</floatpart.length();i++){<></integerpart.length();i++){<>。
数字金额大写转换器制作代码分享(人民币大写转换)
数字⾦额⼤写转换器制作代码分享(⼈民币⼤写转换)复制代码代码如下:/// <summary>/// ⼈民币⼤写/// </summary>/// <param name="input">待转换输⼊</param>/// <param name="prefix">需要添加⼈民币前缀</param>/// <exception cref="ArgumentException" />/// <returns>转换后的结果</returns>public static string ToCapital(this string input, bool prefix = false) {#region Step1 输⼊有效性验证if (!Regex.IsMatch(input, @"(?<=-|^)\d*\.?\d*$"))throw new ArgumentException("错误的输⼊⾦额!");if (Regex.IsMatch(input, @"^\d{25,}"))throw new ArgumentException("输⼊数据太⼤⽆法转换!");#endregion#region Step2 格式化为中间字符串var positionDic = new Dictionary<int, string> {{0,"F"},{1,"J"},{2,"."},{3,"S"},{4,"B"},{5,"Q"},{6,"W"},{7,"SW"},{8,"BW"},{9,"QW"},{10,"Y"},{11,"SY"},{12,"BY"},{13,"QY"},{14,"WY"},{15,"SWY"},{16,"BWY"},{17,"QWY"},{18,"YY"},{19,"SYY"},{20,"BYY"},{21,"QYY"},{22,"WYY"},{23,"SWYY"},{24,"BWYY"},{25,"QWYY"}};input = Regex.Replace(input, @"^\.", "0.");var integerPart = Regex.Replace(input, @"^-|\..*$", "");var _matchDecimal = Regex.Match(input, @"\.\d*$", RegexOptions.None);var decimalPart = Regex.Replace(_matchDecimal.Success ? Convert.ToDouble(_matchDecimal.Value).ToString("0.00") : "00", @"0\.", "");var processStack = new Stack<string>();var charsArray = (integerPart + decimalPart).Reverse<char>();for (int i = 0; i < charsArray.Count(); i++) {processStack.Push(string.Format("{0}{1}", charsArray.ElementAt(i), positionDic[i]));}//符号处理if (Regex.IsMatch(input, "^-", RegexOptions.None)) {processStack.Push("-");}if (prefix) {processStack.Push("¥");}var process = string.Empty;while (processStack.Count > 0) {process += processStack.Pop();}//语义处理模式队列Queue<Tuple<string, string, MatchEvaluator>> patterns = new Queue<Tuple<string, string, MatchEvaluator>>();var patternBuilder = new StringBuilder();for (int i = 3; i < positionDic.Count; i++) {patternBuilder.AppendFormat("{0}{1}", (i == 3 ? "(0(?:" : "") + positionDic[i], i == positionDic.Count - 1 ? ")+?)+" : "|");}patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(patternBuilder.ToString(), "0", null));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"(?:\d+(?:QW|BW|SW|W|Q|B|S)?\d?YY)+", null, m => m.Value.Replace("YY", "") + "YY"));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"(?:\d+(?:QW|BW|SW|W|Q|B|S)?\d?Y)+", null, m => m.Value.Replace("Y", "") + "Y"));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"(?:\d+(?:Q|B|S)?\d?W)+", null, m =>m.Value.Replace("W", "") + "W"));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"(?!^)0+\.", ".", null));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"^0\.0J|^0\.", "", null));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>("0J|0F", "0", null));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>("J0?$", "JZ", null));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"\.$|\.0+$", ".Z", null));patterns.Enqueue(Tuple.Create<string, string, MatchEvaluator>(@"^0+$|^[^.]{0}$", "0.Z", null));while (patterns.Count > 0) {var pattern = patterns.Dequeue();if (pattern.Item3 != null) {process = Regex.Replace(process, pattern.Item1, pattern.Item3);}else {process = Regex.Replace(process, pattern.Item1, pattern.Item2);}}#endregion#region Step3 翻译中间字符串StringBuilder result = new StringBuilder();var translatorDic = new Dictionary<char, string> {{'0',"零"},{'1',"壹"},{'2',"贰"},{'3',"叁"},{'4',"肆"},{'5',"伍"},{'6',"陆"},{'7',"柒"},{'8',"捌"},{'9',"玖"},{'S',"拾"},{'B',"佰"},{'Q',"仟"},{'W',"萬"},{'Y',"亿"},{'¥',"⼈民币"},{'-',"负"},{'.',"圆"},{'J',"⾓"},{'F',"分"},{'Z',"整"}};for (int i = 0; i < process.Length; i++) {result.Append(translatorDic[process[i]]);}#endregionreturn result.ToString();}。
利用Word宏把数字金额小写“变”大写
利用Word宏把数字金额小写“变”大写在日常的办公应用中,尤其是作为一名财务人员,经常需要输入大写金额的形式的数字,“肆仟叁佰五拾元零伍分”,如果用手工输入的话,显得比较麻烦,其实只要通过输入小写数字并通过如下两招就能达到快速输入的目的。
启动Word后按下Alt+F11组合键,在打开的工程窗口左侧双击“ThisDocument”进入代码编写窗口,在代码编辑窗口中输入如下代码:Option ExplicitSub 小写金额变大写()Dim Numeric As Currency, IntPart As Long, DecimalPart As Byte, MyField As Field, Lable As StringDim Jiao As Byte, Fen As Byte, Oddment As String, Odd As String, MyChinese As StringConst ZWDX As String = "壹贰叁肆伍陆柒捌玖零" '定义一个中文大写汉字常量On Error Resume Next '错误忽略With SelectionNumeric = VBA.Round(VBA.Val(.Text), 2) '四舍五入保留小数点后两位'判断是否在表格中If .Information(wdWithInTable) Then _.MoveRight unit:=wdCell Else .MoveRight unit:=wdCharacter'对数据进行判断,是否在指定的范围内If VBA.Abs(Numeric) > 2147483647 Then MsgBox "数值超过范围!", _v bOKOnly + vbExclamation, "Warning": Exit SubIntPart = Int(VBA.Abs(Numeric)) '定义一个正整数Odd = VBA.IIf(IntPart = 0, "", "元") '定义一个STRING变量'插入中文大写前的标签Lable = VBA.IIf(Numeric = VBA.Abs(Numeric), "人民币金额大写: ", "人民币金额大写: 负")'对小数点后面二位数进行择定DecimalPart = (VBA.Abs(Numeric) - IntPart) * 100Select Case DecimalPartCase Is = 0 '如果是0,即是选定的数据为整数Oddment = VBA.IIf(Odd = "", "", Odd & "整")Case Is < 10 '<10,即是零头是分Oddment = VBA.IIf(Odd <> "", "元零" & VBA.Mid(ZWDX, DecimalPart, 1) & "分", _VBA.Mid(ZWDX, DecimalPart, 1) & "分")Case 10, 20, 30, 40, 50, 60, 70, 80, 90 '如果是角整Oddment = "元" & VBA.Mid(ZWDX, DecimalPart / 10, 1) & "角整"Case Else '既有角,又有分的情况Jiao = VBA.Left(CStr(DecimalPart), 1) '取得角面值Fen = VBA.Right(CStr(DecimalPart), 1) '取得分面值Oddment = Odd & VBA.Mid(ZWDX, Jiao, 1) & "角" '转换为角的中文大写Oddment = Oddment & VBA.Mid(ZWDX, Fen, 1) & "分" '转换为分的中文大写End Select'指定区域插入中文大写格式的域Set MyField = .Fields.Add(Range:=.Range, Text:="= " & IntPart & " \*CHINESENUM2")MyField.Select '选定域(最后是用指定文本覆盖选定区域)'如果仅有角分情况下,Mychinese为""MyChinese = VBA.IIf(MyField.Result <> "零", MyField.Result, "").Text = Lable & MyChinese & OddmentEnd WithEnd Sub人民币金额大写:输入完毕后按下Alt+Q键返回word中,以后只需要依次选中需要转换的小写金额后,按下Alt+F8打开宏对话框,选择“小写金额变大写”宏,并单击“运行”即可快速地得出大写金额。
Excel中金额大小写转换(四舍五入都OK)
Excel中金额大小写转换(四舍五入都OK)工程造价,财务常用,小写金额自动转换为大写金额,四舍五入都OK Excel中金额大小写转换编制工程造价很有用编制EXCEL财务表也很有用Excel中金额大小写转换函数[=ntoc(单元格)]一、使用加载宏方法:对于有四舍五入都没问题啊“工具栏”→ “宏”→ “Visual Basic编辑器”,在“Visual Basic编辑器”中顶部选“插入”→ “模块”,在“模块”对话框中选“通用”,并在编辑区域内粘贴以下内容:Function NtoC(n) 'n as singleConst cNum = "零壹贰叁肆伍陆柒捌玖-万仟佰拾亿仟佰拾万仟佰拾元角分"Const cCha = "零仟零佰零拾零零零零零亿零万零元亿万零角零分零整-零零零零零亿万元亿零整整" NtoC = ""n = Round(n, 2)sNum = Trim(Str(Int(n * 100)))For i = 1 To Len(sNum) '逐位转换NtoC = NtoC + Mid(cNum, (Mid(sNum, i, 1)) + 1, 1) + Mid(cNum, 26 - Len(sNum) + i, 1)NextFor i = 0 To 11 '去掉多余的零NtoC = Replace(NtoC, Mid(cCha, i * 2 + 1, 2), Mid(cCha, i + 26, 1))NextEnd Function然后单击“保存”,关闭“Visual Basic编辑器”,回到“工作表1”,输入函数“=NtoC(单元格)”即可。
例如在单元格A1输入:A1=222, 在单元格A2输入:A2=NTOC(A1) 即可,这样A1单元格输入的数变化,A2单元格的大写自动变化。
A2单元格最好进行单元锁定。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
private Function hhhh(i As Range)
If i.Value >= 1 Then
If Int(i) = i Or Round(i, 2) = Int(i) Then
hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元整"
ElseIf Int(i * 10) = i * 10 Or Int(i) * 10 = Round(i, 2) * 10 Then
hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "角整" Else
hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Left(Right(Round(i, 2), 2), 1), "[dbnum2]") & "角" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "分" End If
ElseIf i.Value < 1 And i.Value > 0 Then
If Int(i * 10) = i * 10 Then
hhhh = Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "角"
Else
hhhh = Application.WorksheetFunction.Text(Left(Right(i, 2), 1), "[dbnum2]") & "角" & Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "分"
End If
ElseIf i = o Then hhhh = Application.WorksheetFunction.Text(Int(i), "[dbnum2]") & "元"
Else
If Int(i) = i Then
hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" ElseIf Int(i * 10) = i * 10 Or Round(Abs(i), 2) * 10 = Int(Abs(i)) * 10 Then
hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Right(i, 1), "[dbnum2]") & "角"
Else
hhhh = "负" & Application.WorksheetFunction.Text(Int(Abs(i)), "[dbnum2]") & "元" & Application.WorksheetFunction.Text(Left(Right(Round(i, 2), 2), 1), "[dbnum2]") & "分" & Application.WorksheetFunction.Text(Right(Round(i, 2), 1), "[dbnum2]") & "分" End If
End If
End Function。