This commit is contained in:
hoteas 2018-01-23 18:08:25 +00:00
parent 9bb522d7a0
commit 4498e560d8
5 changed files with 56 additions and 43 deletions

View File

@ -119,7 +119,7 @@ func Random() float64 {
v:=float64(0); v:=float64(0);
m:=float64(0.1); m:=float64(0.1);
for i:=0;i<15;i++{ 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{ for k,_:= range facter{
v=v+float64(k)*m v=v+float64(k)*m

14
map.go
View File

@ -47,6 +47,7 @@ func (this Map) GetInt(key string, err ...*Error) int {
} }
// //唯一标志 // //唯一标志
func (this Map) GetTag() int64 { 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 //获取Float64
func (this Map) GetFloat64(key string, err ...*Error) float64 { func (this Map) GetFloat64(key string, err ...*Error) float64 {

13
obj.go
View File

@ -54,3 +54,16 @@ func (this *Obj) ToObj() interface{} {
return this.Data 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
}

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"strconv" "strconv"
//"strings" "math"
) )
//仅限于hotime.Slice //仅限于hotime.Slice
@ -132,6 +132,18 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 {
return v 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 { func ObjToInt64(obj interface{}, e ...*Error) int64 {
var err error var err error
@ -178,47 +190,8 @@ func ObjToInt64(obj interface{}, e ...*Error) int64 {
} }
func ObjToInt(obj interface{}, e ...*Error) int { func ObjToInt(obj interface{}, e ...*Error) int {
var err error v:=ObjToInt64(obj,e...)
v := 0 return int(v)
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
} }
func ObjToStr(obj interface{}) string { func ObjToStr(obj interface{}) string {

View File

@ -27,6 +27,19 @@ func (this Slice) GetInt64(key int, err ...*Error) int64 {
return v 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 //获取Float64
func (this Slice) GetFloat64(key int, err ...*Error) float64 { func (this Slice) GetFloat64(key int, err ...*Error) float64 {
v := ObjToFloat64((this)[key], err...) v := ObjToFloat64((this)[key], err...)