-
Notifications
You must be signed in to change notification settings - Fork 13
/
decimal.go
73 lines (60 loc) · 1.84 KB
/
decimal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gomini
import(
"github.com/shopspring/decimal"
)
//decimal add to string
func DecimalAddToString(f1,f2 float64,round int) string{
return DecimalAdd(f1,f2).StringFixed(int32(round))
}
//decimal sub to string
func DecimalSubToString(f1,f2 float64,round int) string{
return DecimalSub(f1,f2).StringFixed(int32(round))
}
//decimal mul to string
func DecimalMulToString(f1,f2 float64,round int) string{
return DecimalMul(f1,f2).StringFixed(int32(round))
}
//decimal div to string
func DecimalDivToString(f1,f2 float64,round int) string{
return DecimalDiv(f1,f2).StringFixed(int32(round))
}
//decimal add to float
func DecimalAddToFloat(f1,f2 float64,round int) float64{
f,_:=DecimalAdd(f1,f2).Round(int32(round)).Float64()
return f
}
//decimal sub to float
func DecimalSubToFloat(f1,f2 float64,round int) float64{
f,_:=DecimalSub(f1,f2).Round(int32(round)).Float64()
return f
}
//decimal mul to float
func DecimalMulToFloat(f1,f2 float64,round int) float64{
f,_:=DecimalMul(f1,f2).Round(int32(round)).Float64()
return f
}
//decimal div to float
func DecimalDivToFloat(f1,f2 float64,round int) float64{
f,_:=DecimalDiv(f1,f2).Round(int32(round)).Float64()
return f
}
//decimal add
func DecimalAdd(f1,f2 float64) decimal.Decimal{
return decimal.RequireFromString(GetFloat64Str(f1)).
Add(decimal.RequireFromString(GetFloat64Str(f2)))
}
//decimal sub
func DecimalSub(f1,f2 float64) decimal.Decimal{
return decimal.RequireFromString(GetFloat64Str(f1)).
Sub(decimal.RequireFromString(GetFloat64Str(f2)))
}
//decimal mul
func DecimalMul(f1,f2 float64) decimal.Decimal{
return decimal.RequireFromString(GetFloat64Str(f1)).
Mul(decimal.RequireFromString(GetFloat64Str(f2)))
}
//decimal div
func DecimalDiv(f1,f2 float64) decimal.Decimal{
return decimal.RequireFromString(GetFloat64Str(f1)).
Div(decimal.RequireFromString(GetFloat64Str(f2)))
}