回答編集履歴
1
コードブロックとコードの修正
test
CHANGED
@@ -1,12 +1,56 @@
|
|
1
1
|
ちと出先なので動くか確認できてないですが、こんな感じになるのではないかと思います
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
Jan 17, 2020 PM1:10追記 動いていなかったので修正
|
2
6
|
|
3
7
|
|
4
8
|
|
5
9
|
```js
|
6
10
|
|
11
|
+
const rounded = [
|
12
|
+
|
13
|
+
1000,
|
14
|
+
|
15
|
+
1200,
|
16
|
+
|
17
|
+
999,
|
18
|
+
|
19
|
+
1999,
|
20
|
+
|
21
|
+
9,
|
22
|
+
|
23
|
+
112.35813,
|
24
|
+
|
25
|
+
-14142.1356
|
26
|
+
|
27
|
+
].map(x => roundUpWithFirst2Digit(x));
|
28
|
+
|
29
|
+
document.write(`<ul><li>${rounded.join('</li><li>')}</li></ul>`);
|
30
|
+
|
31
|
+
/*
|
32
|
+
|
33
|
+
1000
|
34
|
+
|
35
|
+
1200
|
36
|
+
|
37
|
+
1000
|
38
|
+
|
39
|
+
2000
|
40
|
+
|
41
|
+
10
|
42
|
+
|
43
|
+
120
|
44
|
+
|
45
|
+
-14000
|
46
|
+
|
47
|
+
*/
|
48
|
+
|
49
|
+
|
50
|
+
|
7
51
|
function roundUpWithFirst2Digit(x) {
|
8
52
|
|
9
|
-
const digit
|
53
|
+
const digitLength = ('' + Math.abs(Math.trunc(x))).length;
|
10
54
|
|
11
55
|
switch(digitLength) {
|
12
56
|
|
@@ -16,10 +60,12 @@
|
|
16
60
|
|
17
61
|
default:
|
18
62
|
|
19
|
-
const multi = 10 ** digitLength
|
63
|
+
const multi = 10 ** (digitLength - 2);
|
20
64
|
|
21
|
-
return Math.ceil(x
|
65
|
+
return Math.ceil(x / multi) * multi;
|
22
66
|
|
23
67
|
}
|
24
68
|
|
25
69
|
}
|
70
|
+
|
71
|
+
```
|