From c10486b4038fe152db19f355c3c25ad5dcebf3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 30 Nov 2024 22:04:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BD=9C=E5=9C=A8=E7=9A=84?= =?UTF-8?q?=E4=B8=A2=E5=A4=B1=E7=B2=BE=E5=BA=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filter.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/filter.go b/filter.go index 3e59717..b5b1767 100644 --- a/filter.go +++ b/filter.go @@ -13,6 +13,8 @@ import ( "reflect" "strings" + "git.zhangdeman.cn/zhangdeman/util" + "git.zhangdeman.cn/zhangdeman/consts" "git.zhangdeman.cn/zhangdeman/json_filter/gjson_hack" "git.zhangdeman.cn/zhangdeman/serialize" @@ -242,7 +244,15 @@ func (f *filter) getValue(dataType consts.DataType, sourceValue gjson.Result, de return strVal.Value(), nil case consts.DataTypeAny: if sourceValue.Exists() { - // TODO : 可能存在精度丢失 + // 可能存在精度丢失, 原因 : gjson.Value 内置的转换, int64 超过一定大小会存在丢失精度问题 + if sourceValue.Num > 0 { + // 说明是数字 + var res float64 + if err := util.ConvertAssign(&res, sourceValue.String()); nil != err { + return nil, err + } + return res, nil + } return sourceValue.Value(), nil } return defaultValue, nil