質問編集履歴

1

みなさま、申し訳ありません。また、ご指摘くださりありがとうございます。ソースを追加しました。

2017/08/01 04:17

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
 
9
9
  ###該当のソースコード
10
+
11
+ ```
10
12
 
11
13
  <section>
12
14
 
@@ -25,6 +27,80 @@
25
27
  </section>
26
28
 
27
29
 
30
+
31
+ ```
32
+
33
+ ```
34
+
35
+
36
+
37
+ function toKanji(n) {
38
+
39
+ var th = ["","千","二千","三千","四千","五千","六千","七千","八千","九千"];
40
+
41
+ var h = ["","百","二百","三百","四百","五百","六百","七百","八百","九百"];
42
+
43
+ var t = ["","十","二十","三十","四十","五十","六十","七十","八十","九十"];
44
+
45
+ var o = ["","一","二","三","四","五","六","七","八","九"];
46
+
47
+ var str = '';
48
+
49
+ var s = '';
50
+
51
+ var m = '';
52
+
53
+
54
+
55
+ if (n == 0) {
56
+
57
+ return '零';
58
+
59
+ } else if (n < 0 || isNaN(n)) {
60
+
61
+ return alert('漢数字に変換できません。');
62
+
63
+ } else {
64
+
65
+ for (var i = 0; i < n.length; i++) {
66
+
67
+ s = n.substr(,); //
68
+
69
+
70
+
71
+ th = th [ Math.floor(s / 1000) ];
72
+
73
+ h = h [ Math.floor(s / 100) % 10 ];
74
+
75
+ t = t [ Math.floor(s / 10) % 10 ];
76
+
77
+ o = o [ s % 10 ];
78
+
79
+ m = th + h + t + o ;
80
+
81
+ str += m ;
82
+
83
+ }
84
+
85
+ return str;
86
+
87
+ }
88
+
89
+ }
90
+
91
+
92
+
93
+ function convert() {
94
+
95
+ var n = document.getElementById('num').value;
96
+
97
+ var result = document.getElementById('result');
98
+
99
+ result.innerHTML = toKanji(n);
100
+
101
+ }
102
+
103
+ ```
28
104
 
29
105
  ###補足情報(言語/FW/ツール等のバージョンなど)
30
106
 
@@ -51,3 +127,13 @@
51
127
  10001 = 一万一
52
128
 
53
129
  1001 = 千一
130
+
131
+
132
+
133
+ どうすればできるのか考えてみたのですが、
134
+
135
+ 4桁ずつ切り出し漢数字へ変換
136
+
137
+ →4桁ごとに桁を追加
138
+
139
+ →if文で4桁の中身が空欄だったら桁つけない?