From 5087636791bac67acda9859d26a35ab8acf60299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Tue, 16 May 2023 11:56:51 +0800 Subject: [PATCH] =?UTF-8?q?Float=E7=B1=BB=E5=9E=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- define.go | 10 ++++++++++ float.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/define.go b/define.go index 7be8ea1..2bf0ae3 100644 --- a/define.go +++ b/define.go @@ -254,6 +254,16 @@ type Float32Result struct { Err error } +// Float32PtrResult ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:10 2023/5/16 +type Float32PtrResult struct { + Value *float32 + Err error +} + // Float64Result ... // // Author : go_developer@163.com<白茶清欢> diff --git a/float.go b/float.go index 7179322..1693b37 100644 --- a/float.go +++ b/float.go @@ -37,6 +37,25 @@ func (f Float) ToFloat32() Float32Result { return res } +// ToFloat32Ptr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:10 2023/5/16 +func (f Float) ToFloat32Ptr() Float32PtrResult { + res := f.ToFloat32() + if nil != res.Err { + return Float32PtrResult{ + Value: nil, + Err: res.Err, + } + } + return Float32PtrResult{ + Value: &res.Value, + Err: nil, + } +} + // ToFloat64 ... // // Author : go_developer@163.com<白茶清欢> @@ -55,6 +74,25 @@ func (f Float) ToFloat64() Float64Result { return res } +// ToFloat64Ptr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:11 2023/5/16 +func (f Float) ToFloat64Ptr() Float64PtrResult { + res := f.ToFloat64() + if nil != res.Err { + return Float64PtrResult{ + Value: nil, + Err: res.Err, + } + } + return Float64PtrResult{ + Value: &res.Value, + Err: nil, + } +} + // ToString ... // // Author : go_developer@163.com<白茶清欢> @@ -73,3 +111,22 @@ func (f Float) ToString() StringResult { Err: nil, } } + +// ToStringPtr ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 11:56 2023/5/16 +func (f Float) ToStringPtr() StringPtrResult { + res := f.ToString() + if nil != res.Err { + return StringPtrResult{ + Value: nil, + Err: res.Err, + } + } + return StringPtrResult{ + Value: &res.Value, + Err: nil, + } +}