<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>Montant converti en majuscule</title>
</head>
<body>
<div>
<h2>Montant converti en lettres majuscules</h2>
<lable for="montant">Veuillez saisir le montant : ¥< ;/lable>
<input id="montant" type="text" />
<p></p>
<bouton onclick="change()">Cliquez convertir< ;/button>
<p id="demo"></p>
</div>
<script type="text/javascript">
function change(){
var money=document.getElementById("amount").value;
document.getElementById("demo").innerHTML =toCapitalization(money);
}
function toCapitalization(money){
var capitalization="";
var unitInt="整";
if(isAmount(money)){
if(money= =parseInt(money)){
var l=getlength(money);
if(l>=10){
capitalization="您输入的金额过大!";
}else{
capitalization= getCap(money,l,0,l)+unitInt;
}
}else{
var mPstr=money+"";
var m=mPstr.split(".");
var mPInt=m [0]. seInt(mPPoint);
capitalisation=getCap(numI ,getlength(numI),0,len)
+getCap(numP,getlength(numP),1,len);
}
}else{
capitalization="请输入正确的金额!";
}
return majuscule;
}
function getlength(num){
var str=num+"";
return str.length;
}
function isAmount(num){
var ret=/ ^(([1-9][0-9]*)|((([0])|([1-9][0-9]*)).(([1-9])|([ 0-9][1-9])))|([0]))$/;
if(ret.test(num)){
return true;
}else{
return false;
}
}
fonction gerArray(num,l,k,len){
var nums=[];
if(k==1 && l!=len){
nums[0]=0 ;
nums[1]=num;
}else{
for(i=1;i<=l;i++){
nums[l-i]=num%10;
if(l-i> 0){
num=(num-nums[l-i])/10;
}
}
}
return nums;
}
function getUnit(i,k){
//k =0 nombre de points k=1 nombre de points k=1 nombre de points var unit=["圆","拾","佰","仟","万","拾","佰","仟","亿"];
var unitPoint=["角","分"];
if(i<9 && k==0){
retourner l'unité[i];
}else if(i<2 && k==1){
return unitPoint[i];
}
}
function getNumber(i){
var capitalization=["零","壹","贰","叁" ,"肆","伍","陆","柒","捌","玖"];
retourner la majuscule[i];
}
fonction getCap(num,l,k,len) {
var nums=gerArray(num,l,k,len);
var str='';
if(k==0){
for(i=0;i<l;i++){
str=str+getNumber(nums[i])+getUnit(l-i-1,k);
}
}else{
for(i=0;i<len;i++){
str=str +getNumber(nums[i])+getUnit(i,k);
}
}
return str;
}
</script>
</body>
</html> ;