回答編集履歴

2

おまけ

2017/09/06 06:22

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -7,3 +7,27 @@
7
7
  return "%,d".format(value.toLong())
8
8
 
9
9
  ```
10
+
11
+
12
+
13
+ # おまけ
14
+
15
+
16
+
17
+ ```kotlin
18
+
19
+ fun Int.toStringWithSeparator() = this.toString().reversed().withIndex().map {it.value + if ((it.index-1) % 3 == 2) "," else ""}.reversed().joinToString(separator = "")
20
+
21
+
22
+
23
+ println(1234567890.toStringWithSeparator())
24
+
25
+ //=> 1,234,567,890
26
+
27
+ ```
28
+
29
+
30
+
31
+ 負値には対応していませんw
32
+
33
+

1

3

2017/09/06 06:22

投稿

fuzzball
fuzzball

スコア16731

test CHANGED
@@ -4,6 +4,6 @@
4
4
 
5
5
  ```kotlin
6
6
 
7
- return "%,3d".format(value.toLong())
7
+ return "%,d".format(value.toLong())
8
8
 
9
9
  ```