From 6ecdd575aa8733639af2810a43e4af74989ccee2 Mon Sep 17 00:00:00 2001 From: hoteas Date: Sun, 28 Jan 2018 17:30:47 +0000 Subject: [PATCH] --- map.go | 5 +++++ obj.go | 16 ++++++++++++++++ objtoobj.go | 16 ++++++++++++---- slice.go | 6 ++++++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/map.go b/map.go index d38645b..ecbd222 100644 --- a/map.go +++ b/map.go @@ -78,7 +78,12 @@ func (this Map) GetCeilInt(key string, err ...*Error) int { return v } +//获取向上取整float64 +func (this Map) GetCeilFloat64(key string, err ...*Error) float64 { + v := ObjToCeilFloat64((this)[key], err...) + return v +} //获取Float64 func (this Map) GetFloat64(key string, err ...*Error) float64 { diff --git a/obj.go b/obj.go index cead9e5..9c17ab0 100644 --- a/obj.go +++ b/obj.go @@ -31,6 +31,16 @@ func (this *Obj) ToFloat64(err ...Error) float64 { return ObjToFloat64(this.Data, &this.Error) } +//获取向上取整float64 +func (this *Obj) ToCeilFloat64(err ...*Error) float64 { + if len(err) != 0 { + this.Error = *err[0] + } + v := ObjToCeilFloat64(this.Data, err...) + return v + +} + func (this *Obj) ToStr() string { return ObjToStr(this.Data) @@ -57,12 +67,18 @@ func (this *Obj) ToObj() interface{} { //获取向上取整Int64 func (this *Obj) ToCeilInt64(err ...*Error) int64 { + if len(err) != 0 { + this.Error = *err[0] + } v := ObjToCeilInt64(this.Data, err...) return v } //获取向上取整Int func (this *Obj) ToCeilInt(err ...*Error) int { + if len(err) != 0 { + this.Error = *err[0] + } v := ObjToCeilInt(this.Data, err...) return v diff --git a/objtoobj.go b/objtoobj.go index 2f3fb78..320ff2c 100644 --- a/objtoobj.go +++ b/objtoobj.go @@ -134,14 +134,22 @@ func ObjToFloat64(obj interface{}, e ...*Error) float64 { } //向上取整 func ObjToCeilInt64(obj interface{}, e ...*Error)int64{ - f:=ObjToFloat64(obj,e...) - return ObjToInt64(math.Ceil(f)) + f:=ObjToCeilFloat64(obj,e...) + return ObjToInt64(math.Ceil(f)) } + +//向上取整 +func ObjToCeilFloat64(obj interface{}, e ...*Error)float64{ + f:=ObjToFloat64(obj,e...) + return math.Ceil(f) + +} + //向上取整 func ObjToCeilInt(obj interface{}, e ...*Error)int{ - f:=ObjToFloat64(obj,e...) - return ObjToInt(math.Ceil(f)) + f:=ObjToCeilFloat64(obj,e...) + return ObjToInt(f) } diff --git a/slice.go b/slice.go index cbb8c00..2f07fae 100644 --- a/slice.go +++ b/slice.go @@ -38,6 +38,12 @@ func (this Slice) GetCeilInt(key int, err ...*Error) int { v := ObjToCeilInt((this)[key], err...) return v +} +//获取向上取整float64 +func (this Slice) GetCeilFloat64(key int, err ...*Error) float64 { + v := ObjToCeilFloat64((this)[key], err...) + return v + } //获取Float64