From fea7325f3b1abc55fc7fc467129723b6d85ac7f0 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期五, 02 八月 2019 16:09:08 +0800
Subject: [PATCH] 数值精度保留

---
 ruleserver/readyDataForRule.go |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/ruleserver/readyDataForRule.go b/ruleserver/readyDataForRule.go
index c8a1d68..4c8ffcc 100644
--- a/ruleserver/readyDataForRule.go
+++ b/ruleserver/readyDataForRule.go
@@ -8,6 +8,7 @@
 	"fmt"
 	"github.com/go-yaml/yaml"
 	"io/ioutil"
+	"math"
 	"ruleprocess/cache"
 	"ruleprocess/logger"
 	"strconv"
@@ -92,9 +93,10 @@
 	// float32涓巉loat64浜掕浆浼氭湁浣嶆暟淇濈暀涓嶅噯鐨勯棶棰�
 	return v
 }
-func Decimal(value float64) float64 {
-	value, _ = strconv.ParseFloat(fmt.Sprintf("%.4f", value), 64)
-	return value
+func Decimal(value float32) float64 {
+	value1, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", float64(value)), 64)
+	n10 := math.Pow10(4)
+	return math.Trunc((value1+0.5/n10)*n10) / n10
 }
 // 鍙栧嚭鏌愪釜鏃堕棿瑙勫垯鐨勭鍑犲ぉ鐨勮鍒欐闆嗗悎
 func GetTimeById(id string, index int) []TimeRange {
@@ -181,8 +183,8 @@
 			if err != nil || len(table) == 0 {
 				logger.Error("鏍规嵁id鏌ヨ搴曞簱淇℃伅鍑洪敊锛�", err, "--杩斿洖鍊奸暱搴︿负锛�", len(table))
 			}
-			logger.Debug("鐪嬬湅杩欎釜base鐨勫姣斿�兼槸澶氬皯锛�",Retain(m[baseinfo.Id]) * 100)
-			base := BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(float64(m[baseinfo.Id])) * 100, PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved}
+			logger.Debug("鐪嬬湅杩欎釜base鐨勫姣斿�兼槸澶氬皯锛�", Decimal(m[baseinfo.Id]) * 100)
+			base := BaseInfo{TableId: baseinfo.TableId, TableName: table[0].TableName, BwType: table[0].BwType, CompareScore: Decimal(m[baseinfo.Id]) * 100, PersonId: baseinfo.Id, PersonName: baseinfo.PersonName, PersonPicUrl: baseinfo.PersonPicUrl, PhoneNum: baseinfo.PhoneNum, Sex: baseinfo.Sex, IdCard: baseinfo.IdCard, MonitorLevel: baseinfo.MonitorLevel, Content: baseinfo.Reserved}
 			//os.Exit(1)
 			arg.Liker = append(arg.Liker, &base)
 		}

--
Gitblit v1.8.0