diff --git a/big_output.go b/big_output.go index 85a8e52..7b1a7a8 100644 --- a/big_output.go +++ b/big_output.go @@ -2,6 +2,7 @@ package godecimal import ( "fmt" + "math" "math/big" "strings" ) @@ -36,8 +37,8 @@ func (d Decimal) Float64Point(p int) float64 { func (d Decimal) Float64PointAdaptive(maxP int) float64 { f, _ := d.floatValue.Float64() if maxP > 0 { - pointLength := d.pointLength(f) - if pointLength > maxP { + pL := d.pointLength(f) + if pL > maxP { rat, _ := new(big.Rat).SetString(d.floatValue.Text('f', maxP)) f2, _ := rat.Float64() return f2 @@ -56,3 +57,12 @@ func (Decimal) pointLength(a any) int { } return len(tmp[1]) } + +// IsInteger 是否为整数 +func (d Decimal) IsInteger(d2 float64) bool { + f3 := NewFloat(d.Float64()).QuoFloat(NewFloat(d2).Float64()).Float64() + if f3 == math.Trunc(f3) { + return true + } + return false +} diff --git a/go.mod b/go.mod index 38edac9..966b051 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module go.dtapp.net/godecimal go 1.19 + +require github.com/shopspring/decimal v1.3.1 diff --git a/go.sum b/go.sum index e69de29..3289fec 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= diff --git a/version.go b/version.go index f083e35..f46c0b0 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,3 @@ package godecimal -const Version = "1.0.7" +const Version = "1.0.8"