修复error输出错误问题

This commit is contained in:
2023-05-05 16:07:42 +08:00
parent b182b21e03
commit fa2f27724d
3 changed files with 30 additions and 18 deletions

View File

@ -26,7 +26,7 @@ type Float float64
// Date : 14:36 2023/5/5
func (f Float) ToFloat32() (float32, error) {
if f > math.MaxFloat32 || f < math.SmallestNonzeroFloat32 {
return 0, fmt.Errorf("float32 should between %v and %v", math.SmallestNonzeroFloat32, math.MaxFloat32)
return 0, fmt.Errorf("float32 should between %v and %v", float32(math.SmallestNonzeroFloat32), float32(math.MaxFloat32))
}
return float32(f), nil
}
@ -38,7 +38,7 @@ func (f Float) ToFloat32() (float32, error) {
// Date : 14:36 2023/5/5
func (f Float) ToFloat64() (float64, error) {
if f > math.MaxFloat64 || f < math.SmallestNonzeroFloat64 {
return 0, fmt.Errorf("float32 should between %v and %v", math.SmallestNonzeroFloat64, math.MaxFloat64)
return 0, fmt.Errorf("float32 should between %v and %v", float64(math.SmallestNonzeroFloat64), float64(math.MaxFloat64))
}
return float64(f), nil
}
@ -48,6 +48,10 @@ func (f Float) ToFloat64() (float64, error) {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 14:38 2023/5/5
func (f Float) ToString() string {
return fmt.Sprintf("%v", f)
func (f Float) ToString() (string, error) {
floatVal, err := f.ToFloat64()
if nil != err {
return "", err
}
return fmt.Sprintf("%v", floatVal), nil
}