回答編集履歴
2
修正
test
CHANGED
@@ -21,3 +21,43 @@
|
|
21
21
|
Console.WriteLine(d); //4.204E-42
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
---
|
26
|
+
|
27
|
+
(2021/11/18 19:42 追記)
|
28
|
+
|
29
|
+
d<=0、d_log10==0の時に死ぬので、少し修正しました。
|
30
|
+
|
31
|
+
```cs
|
32
|
+
|
33
|
+
if( d!=0 && !double.IsNaN(d) && !double.IsInfinity(d) )
|
34
|
+
|
35
|
+
{
|
36
|
+
|
37
|
+
var d_log10 = Math.Floor(Math.Log10(Math.Abs(d)));
|
38
|
+
|
39
|
+
if(d_log10 != 0 )
|
40
|
+
|
41
|
+
{
|
42
|
+
|
43
|
+
var pow_idx = Math.Pow(10, -d_log10);
|
44
|
+
|
45
|
+
d *= pow_idx;
|
46
|
+
|
47
|
+
d = Math.Round(d, 3, MidpointRounding.AwayFromZero);
|
48
|
+
|
49
|
+
d /= pow_idx;
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
else
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
d = Math.Round(d, 3, MidpointRounding.AwayFromZero);
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|
1
修正
test
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
var d = 4.20365978E-42;
|
6
6
|
|
7
|
-
var
|
7
|
+
var d_log10 = Math.Floor(Math.Log10(d)); //E-42の-42を計算
|
8
8
|
|
9
|
-
var pow_idx = Math.Pow(10, -
|
9
|
+
var pow_idx = Math.Pow(10, -d_log10); //E-42を取り除く為の乗数
|
10
10
|
|
11
11
|
|
12
12
|
|