diff --git a/func.go b/func.go index c2473bf..90b7236 100644 --- a/func.go +++ b/func.go @@ -119,7 +119,7 @@ func Random() float64 { v:=float64(0); m:=float64(0.1); for i:=0;i<15;i++{ - facter:=map[int]int{0:1,9:1,2:1,7:1,4:1,5:1,6:1,3:1,8:1,1:1} + facter:=map[int]int{4:1,9:1,2:1,3:1,1:1,7:1,0:1,5:1,6:1,8:1,} for k,_:= range facter{ v=v+float64(k)*m diff --git a/map.go b/map.go index c553138..d38645b 100644 --- a/map.go +++ b/map.go @@ -47,6 +47,7 @@ func (this Map) GetInt(key string, err ...*Error) int { } + // //唯一标志 func (this Map) GetTag() int64 { @@ -65,6 +66,19 @@ func (this Map) GetInt64(key string, err ...*Error) int64 { } +//获取向上取整Int64 +func (this Map) GetCeilInt64(key string, err ...*Error) int64 { + v := ObjToCeilInt64((this)[key], err...) + return v + +} +//获取向上取整Int +func (this Map) GetCeilInt(key string, err ...*Error) int { + v := ObjToCeilInt((this)[key], err...) + return v + +} + //获取Float64 func (this Map) GetFloat64(key string, err ...*Error) float64 { diff --git a/obj.go b/obj.go index 60f5c1d..cead9e5 100644 --- a/obj.go +++ b/obj.go @@ -54,3 +54,16 @@ func (this *Obj) ToObj() interface{} { return this.Data } + +//获取向上取整Int64 +func (this *Obj) ToCeilInt64(err ...*Error) int64 { + v := ObjToCeilInt64(this.Data, err...) + return v + +} +//获取向上取整Int +func (this *Obj) ToCeilInt(err ...*Error) int { + v := ObjToCeilInt(this.Data, err...) + return v + +} \ No newline at end of file diff --git a/objtoobj.go b/objtoobj.go index 8a72ae8..2f3fb78 100644 --- a/objtoobj.go +++ b/objtoobj.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "strconv" - //"strings" + "math" ) //仅限于hotime.Slice @@ -132,6 +132,18 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 { return v } +//向上取整 +func ObjToCeilInt64(obj interface{}, e ...*Error)int64{ + f:=ObjToFloat64(obj,e...) + return ObjToInt64(math.Ceil(f)) + +} +//向上取整 +func ObjToCeilInt(obj interface{}, e ...*Error)int{ + f:=ObjToFloat64(obj,e...) + return ObjToInt(math.Ceil(f)) + +} func ObjToInt64(obj interface{}, e ...*Error) int64 { var err error @@ -178,47 +190,8 @@ func ObjToInt64(obj interface{}, e ...*Error) int64 { } func ObjToInt(obj interface{}, e ...*Error) int { - var err error - v := 0 - if obj == nil { - - err = errors.New("没有合适的转换对象!") - } else { - switch obj.(type) { - case int: - v = obj.(int) - case int64: - v = int(obj.(int64)) - case string: - value, e := StrToInt(obj.(string)) - if e != nil { - v = 0 - err = e - } else { - v = value - } - case uint8: - value, e := StrToInt(obj.(string)) - if e != nil { - v = 0 - err = e - } else { - v = value - } - case float64: - v = int(obj.(float64)) - case float32: - v = int(obj.(float32)) - default: - v = 0 - err = errors.New("没有合适的转换对象!") - - } - } - if len(e) != 0 { - e[0].SetError(err) - } - return v + v:=ObjToInt64(obj,e...) + return int(v) } func ObjToStr(obj interface{}) string { diff --git a/slice.go b/slice.go index 15fb84e..cbb8c00 100644 --- a/slice.go +++ b/slice.go @@ -27,6 +27,19 @@ func (this Slice) GetInt64(key int, err ...*Error) int64 { return v } +//获取向上取整Int64 +func (this Slice) GetCeilInt64(key int, err ...*Error) int64 { + v := ObjToCeilInt64((this)[key], err...) + return v + +} +//获取向上取整Int +func (this Slice) GetCeilInt(key int, err ...*Error) int { + v := ObjToCeilInt((this)[key], err...) + return v + +} + //获取Float64 func (this Slice) GetFloat64(key int, err ...*Error) float64 { v := ObjToFloat64((this)[key], err...)