回答編集履歴
2
おまけ
answer
CHANGED
@@ -2,4 +2,15 @@
|
|
2
2
|
|
3
3
|
```kotlin
|
4
4
|
return "%,d".format(value.toLong())
|
5
|
-
```
|
5
|
+
```
|
6
|
+
|
7
|
+
# おまけ
|
8
|
+
|
9
|
+
```kotlin
|
10
|
+
fun Int.toStringWithSeparator() = this.toString().reversed().withIndex().map {it.value + if ((it.index-1) % 3 == 2) "," else ""}.reversed().joinToString(separator = "")
|
11
|
+
|
12
|
+
println(1234567890.toStringWithSeparator())
|
13
|
+
//=> 1,234,567,890
|
14
|
+
```
|
15
|
+
|
16
|
+
負値には対応していませんw
|
1
3
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
別にKotlinらしくはないですが‥。
|
2
2
|
|
3
3
|
```kotlin
|
4
|
-
return "%,
|
4
|
+
return "%,d".format(value.toLong())
|
5
5
|
```
|