|
@@ -15,19 +15,24 @@ func TestRoundFieldValue(t *testing.T) { |
|
@@ -15,19 +15,24 @@ func TestRoundFieldValue(t *testing.T) { |
15
|
want string
|
15
|
want string
|
16
|
}{
|
16
|
}{
|
17
|
{
|
17
|
{
|
18
|
- v: "0.12359999999999999",
|
18
|
+ v: "0.123599999999999",
|
19
|
f: floatFiled,
|
19
|
f: floatFiled,
|
20
|
- want: "0.1236",
|
20
|
+ want: "0.123599999999999",
|
21
|
},
|
21
|
},
|
22
|
{
|
22
|
{
|
23
|
- v: "0.12360000000000001",
|
23
|
+ v: "0.123600000000001",
|
24
|
f: floatFiled,
|
24
|
f: floatFiled,
|
25
|
- want: "0.1236",
|
25
|
+ want: "0.123600000000001",
|
26
|
},
|
26
|
},
|
27
|
{
|
27
|
{
|
28
|
- v: "0.12359999999999995",
|
28
|
+ v: "0.12359990000000",
|
29
|
f: floatFiled,
|
29
|
f: floatFiled,
|
30
|
- want: "0.1236",
|
30
|
+ want: "0.1235999",
|
|
|
31
|
+ },
|
|
|
32
|
+ {
|
|
|
33
|
+ v: "18749465132.256",
|
|
|
34
|
+ f: floatFiled,
|
|
|
35
|
+ want: "18749465132.256",
|
31
|
},
|
36
|
},
|
32
|
}
|
37
|
}
|
33
|
for _, input := range inputs {
|
38
|
for _, input := range inputs {
|
|
@@ -35,3 +40,39 @@ func TestRoundFieldValue(t *testing.T) { |
|
@@ -35,3 +40,39 @@ func TestRoundFieldValue(t *testing.T) { |
35
|
assert.Equal(t, input.want, got)
|
40
|
assert.Equal(t, input.want, got)
|
36
|
}
|
41
|
}
|
37
|
}
|
42
|
}
|
|
|
43
|
+
|
|
|
44
|
+func TestRoundValue(t *testing.T) {
|
|
|
45
|
+ floatFiled := &Field{
|
|
|
46
|
+ SQLType: Float.ToString(),
|
|
|
47
|
+ }
|
|
|
48
|
+ inputs := []struct {
|
|
|
49
|
+ v string
|
|
|
50
|
+ f *Field
|
|
|
51
|
+ want string
|
|
|
52
|
+ }{
|
|
|
53
|
+ {
|
|
|
54
|
+ v: "0.123599999999999",
|
|
|
55
|
+ f: floatFiled,
|
|
|
56
|
+ want: "0.123599999999999",
|
|
|
57
|
+ },
|
|
|
58
|
+ {
|
|
|
59
|
+ v: "0.123600000000001",
|
|
|
60
|
+ f: floatFiled,
|
|
|
61
|
+ want: "0.123600000000001",
|
|
|
62
|
+ },
|
|
|
63
|
+ {
|
|
|
64
|
+ v: "0.123599999999995",
|
|
|
65
|
+ f: floatFiled,
|
|
|
66
|
+ want: "0.123599999999995",
|
|
|
67
|
+ },
|
|
|
68
|
+ {
|
|
|
69
|
+ v: "18749465132.256",
|
|
|
70
|
+ f: floatFiled,
|
|
|
71
|
+ want: "18749465132.256",
|
|
|
72
|
+ },
|
|
|
73
|
+ }
|
|
|
74
|
+ for _, input := range inputs {
|
|
|
75
|
+ got := RoundValue(input.v)
|
|
|
76
|
+ assert.Equal(t, input.want, got)
|
|
|
77
|
+ }
|
|
|
78
|
+} |