function toKanji(n) {
var th = ["","千","二千","三千","四千","五千","六千","七千","八千","九千"];
var h = ["","百","二百","三百","四百","五百","六百","七百","八百","九百"];
var t = ["","十","二十","三十","四十","五十","六十","七十","八十","九十"];
var o = ["","一","二","三","四","五","六","七","八","九"];
var str = '';
var s = '';
var m = '';
if (n == 0) {
return '零';
} else if (n < 0 || isNaN(n)) {
return alert('漢数字に変換できません。');
} else {
for (var i = 0; i < n.length; i++) {
s = n.substr(,); //
th = th [ Math.floor(s / 1000) ];
h = h [ Math.floor(s / 100) % 10 ];
t = t [ Math.floor(s / 10) % 10 ];
o = o [ s % 10 ];
m = th + h + t + o ;
str += m ;
}
return str;
}
}
function convert() {
var n = document.getElementById('num').value;
var result = document.getElementById('result');
result.innerHTML = toKanji(n);
}
1functiontoKanji4(n){2var th =["","千","二千","三千","四千","五千","六千","七千","八千","九千"];3var h =["","百","二百","三百","四百","五百","六百","七百","八百","九百"];4var t =["","十","二十","三十","四十","五十","六十","七十","八十","九十"];5var o =["","一","二","三","四","五","六","七","八","九"];6var s ='';7var m ='';89if(n ==0){10return'零';11}elseif(n <0||isNaN(n)){12returnalert('漢数字に変換できません。');13}else{14 s = n.substr(-4);15 th = th [Math.floor(s /1000)];16 h = h [Math.floor(s /100)%10];17 t = t [Math.floor(s /10)%10];18 o = o [ s %10];19 m = th + h + t + o ;20return m;21}22}2324functionconvert(){25var n =document.getElementById('num').value;26var result =document.getElementById('result');27 result.innerHTML=toKanji4(n);28}
1n =1000000001203450;23[...(4function*(n){5while( n >=1){6const remainder = n %10000;7 n =parseInt( n /10000);8yield remainder;9}10}11)(n)].map(12n=> n.toLocaleString('ja-JP-u-nu-hanidec',{useGrouping:false}).split('').reverse().map(13(d, i)=>{14if( d =='〇')return'';15if( d =='一')return'一十百千'[i];16return d +' 十百千'[i];17}18).reverse().join('')19).map(20(d, i)=>{21if( d =='千'&& i !=0)return d.replace('千','一千')+" 万億兆"[i];22if( d =='')return'';23return d +" 万億兆"[i];24}25).reverse().join('').split(' ').join('');2627/*
28一千兆百二十万三千四百五十
29*/