大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
package Test;
成都创新互联公司是一家专注于成都做网站、网站设计、外贸营销网站建设与策划设计,高碑店网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:高碑店等地区。高碑店做网站价格咨询:18982081108
import javax.swing.JOptionPane;
public class Test2 {
public static void main(String[] args) {
int numOf10=0;
int numOf5=0;
int numOf1=0;
坦裂 int numOf0_5=0;
int numOf0_1=0;
Double money=Double.parseDouble(JOptionPane.showInputDialog("输入money"));
int total=(int)(money*10);
while(total0){
if((total-100)=0){
悔数 total-=100;
numOf10++;
}else if((total-50)=0){
total-=50;
numOf5++;
}else if((total-10)=0){
total-=10;
numOf1++;
}else if((total-5)=0){
total-=5;
numOf0_5++;
}else if((total-1)=0){
total-=1;
numOf0_1++;
}
}
if(numOf10!=0){
System.out.println("10元人民币:"+numOf10+"张");
}
if(numOf5!=0){
System.out.println("5元人民币:"+numOf5+"张");
}
if(numOf1!=0){
System.out.println("1元人民币:"+numOf1+"张");
}
if(numOf0_5!=0){
System.out.println("5角人民币:"+numOf0_5+"张");
}
if(numOf0_1!=0){
System.out.println("1角人民币让前闭:"+numOf0_1+"张");
}
}
}
java中不可以通过强制转换将true和false转知态换成1和0 因为布尔类型与其他基本类型数据不可族巧以搭穗源互相转换 可以用条件运算符 int a=(b==true)?1:0;//如果b为true则给a赋值1,如果为false则赋值0
publicstatic String toRMB(double money) {
char[] s1 = {'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'};
char[] s4 = {'分', '角', '元', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟', '万'};
//这两句是为后面转换做字典准备
String str = String.valueOf(Math.round(money * 100 + 0.00001));
//这是把参数money小数点后移2位,然后取整,即按照“分”为单位取整,再转为字符串型
String result = "";
for (int i = 0; i str.length(); i++) {
int n = str.charAt(str.length() - 1 - i) - '0';
result = s1[n] + "" + s4[i] + result;
}
//这一段是按照转换出来的字符串按位取数字,再按照上面的字典将其逐位翻译成汉字
//如“2011”就翻译成“贰仟零佰壹拾壹元”,“98700432.10”就是“玖仟捌佰柒拾零万零仟肆佰叁拾贰元壹角零分”——注:这里的人民币大写汉字,貌似有错误,请查阅相关资料更正
//以上的翻纳和译可以洞信盯看出,和我们平时的认读有差别,于是以下就是在将那些应该纠正的地方手动剔除以下。上述两个例子最后得到的结果应该是“贰仟零壹拾壹元整”,“玖仟捌佰柒拾万零肆佰叁拾贰元壹角整”
result = result.replaceAll("零仟", "零");
result = result.replaceAll("零佰", "零");
result = result.replaceAll("零拾", "零");
result = result.replaceAll("零亿", "亿");
result = result.replaceAll("零万", "万");
result = result.replaceAll("零元", "元");
result = result.replaceAll("零角", "零");
result = result.replaceAll("零分", "零");
result = result.replaceAll("零零", "零");
result = result.replaceAll("零亿", "亿");
result = result.replaceAll("零零", "零");
result = result.replaceAll("零万", "万");
result = result.replaceAll("零零", "零");
result = result.replaceAll("零元", "元");
result = result.replaceAll("坦镇亿万","亿");
result = result.replaceAll("零$", "");
result = result.replaceAll("元$", "元整");
result = result.replaceAll("角$", "角整");
return result;
}
//将人民币金额册兆晌转换为大写
function upDigit(n){
var fraction = ["角","分"];
var digit = ["零","壹","贰","叁","肆","伍"州锋,"陆","柒","捌","玖"];
var unit = [["元","万","亿"],[""猜逗,"拾","佰","仟"]];
var head = n0?"负":"";
n = Math.abs(n);
var s = "";
for(var i=0; ifraction.length; i++){
s += (digit[Math.floor(n*10*Math.pow(10,i))%10]+fraction[i]).replace(/零./,"");
}
s = s||"整";
n = Math.floor(n);
for(var i=0; iunit[0].length n0; i++){
var p = "";
for(var j=0; junit[1].length n0; j++){
p = digit[n%10] + unit[1][j]+p;
n = Math.floor(n/10);
}
s = p.replace(/(零.)*零$/,"").replace(/^$/,"零") + unit[0][i] + s;
}
return head + s.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/(^整$)/,"零元整");
}