master v1.0.11
dtapps 4 months ago
parent 537950e68f
commit cb4c11ed29

@ -12,8 +12,8 @@
#### 安装
```go
go get -v -u go.dtapp.net/godecimal
```shell
go get -v -u go.dtapp.net/godecimal@v1.0.11
```
#### 使用

@ -1,5 +1,14 @@
package godecimal
import "fmt"
// NewInterface 创建
func NewInterface(value interface{}) Decimal {
d := New()
d.floatValue.SetString(fmt.Sprint(value))
return d
}
// NewString 从字符串创建
func NewString(s string) Decimal {
d := New()

@ -1,3 +0,0 @@
package godecimal
const Version = "1.0.10"

@ -1,3 +1,3 @@
module go.dtapp.net/godecimal
go 1.19
go 1.21

@ -0,0 +1,35 @@
package godecimal
import (
"database/sql/driver"
"fmt"
"strings"
)
type DFloat struct {
FValue float64
Point int
}
// Value 实现 driver.Valuer 接口Value 返回 json value
func (f DFloat) Value() (driver.Value, error) {
return NewFloat(f.FValue).Float64PointAdaptive(f.Point), nil
}
// Scan 方法实现了 sql.Scanner 接口
func (f *DFloat) Scan(value interface{}) error {
f1, _ := value.(float64)
*f = DFloat{
FValue: f1,
Point: pointLength(f1),
}
return nil
}
func pointLength(a any) int {
tmp := strings.Split(fmt.Sprint(a), ".")
if len(tmp) <= 1 {
return 0
}
return len(tmp[1])
}

@ -0,0 +1,3 @@
package godecimal
const Version = "1.0.11"
Loading…
Cancel
Save