---
title: "大小写金额转换"
author: "zwfc"
date: "2007-12-02T15:55:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2007-12-02T15:55:00Z"
id: 470957
url: "https://zwfc.iteye.com/blog/470957"
---

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)//整数金额转化成中国传统大写金额表示形式。  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)packagecom.mjm;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)importjava.util.Scanner;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)publicclassMoneyformat...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)/\*\*\*//\**  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)\*@paramargs  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)\*/  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicstaticvoidmain(String\[]args)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//TODOAuto-generatedmethodstub  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)System.out.println("请输入你要转化的金额...");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Scannerin=newScanner(System.in);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intmoney=in.nextInt();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)System.out.println(Moneyformat.change(money));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)publicstaticStringchange(intn)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Stringstr=Integer.toString(n);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Stringret="";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intlen=str.length();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(inti=0;i&lt;str.length();i++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)intk=Integer.parseInt(str.substring(i,i+1));  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(ret.length()&gt;=1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)&&"佰仟萬".indexOf(ret.substring(ret.length()-1,ret  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif).length()))==-1&&k==0)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+=changeit(-1,len);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)len--;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if(i&lt;str.length()-1)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if((k==0&&Integer  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif).parseInt(str.substring(i,i+1+1))==0))...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)len--;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)continue;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)}elseif(i==str.length()-1&&k==0)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="圆整";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)len--;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)continue;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+=changeit(k,len);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)len--;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnret;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)privatestaticStringchangeit(intn,intlen)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//"零","壹","贰","叁","肆","伍","陆","柒","捌","玖"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)Stringret="";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)switch(n)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case0:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//if(flag==true)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnret="零";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case1:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="壹";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case2:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="贰";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case3:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="叁";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case4:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="肆";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case5:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="伍";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case6:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="陆";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case7:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="柒";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case8:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="捌";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case9:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret="玖";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)//转换成拾，佰，仟，萬，亿  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)switch(len-1)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case0:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="圆整";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case1:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case5:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="拾";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case2:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case6:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="佰";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case3:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case7:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="仟";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case4:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="萬";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)case8:  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)ret+="亿";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)break;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)returnret;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)