作者 yangfu

把握分百分比取整

@@ -15,3 +15,9 @@ func Decimal(value float64) float64 { @@ -15,3 +15,9 @@ func Decimal(value float64) float64 {
15 value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64) 15 value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64)
16 return value 16 return value
17 } 17 }
  18 +
  19 +func DecimalToNumber(value float64) float64 {
  20 + value = decimal(value)
  21 + value, _ = strconv.ParseFloat(fmt.Sprintf("%.f", value), 64)
  22 + return value
  23 +}
@@ -8,4 +8,10 @@ func TestDecimal(t *testing.T) { @@ -8,4 +8,10 @@ func TestDecimal(t *testing.T) {
8 t.Log(Decimal(1.7555555)) 8 t.Log(Decimal(1.7555555))
9 t.Log(Decimal(1.3555555)) 9 t.Log(Decimal(1.3555555))
10 t.Log(Decimal(1.3000001)) 10 t.Log(Decimal(1.3000001))
  11 +
  12 + t.Log(DecimalToNumber(1.0))
  13 + t.Log(DecimalToNumber(1.4))
  14 + t.Log(DecimalToNumber(1.5))
  15 + t.Log(DecimalToNumber(1.6))
  16 + t.Log(DecimalToNumber(99.0))
11 } 17 }
@@ -50,7 +50,7 @@ func AchievementPool(header *protocol.RequestHeader, request *protocol.Achieveme @@ -50,7 +50,7 @@ func AchievementPool(header *protocol.RequestHeader, request *protocol.Achieveme
50 Achievement: GetAchievementItem(header, item), 50 Achievement: GetAchievementItem(header, item),
51 GraspScore: protocol.GraspScore{ 51 GraspScore: protocol.GraspScore{
52 GraspScore: item.UserGraspScore, 52 GraspScore: item.UserGraspScore,
53 - GraspScorePercent: item.UserGraspScore, 53 + GraspScorePercent: utils.DecimalToNumber(item.UserGraspScore),
54 }, 54 },
55 StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId), 55 StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId),
56 ChanceTemplate: getTemplate(item.TemplateId), 56 ChanceTemplate: getTemplate(item.TemplateId),
@@ -137,7 +137,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve @@ -137,7 +137,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
137 rsp.Achievement = GetAchievementItem(header, item) 137 rsp.Achievement = GetAchievementItem(header, item)
138 rsp.GraspScore = protocol.GraspScore{ 138 rsp.GraspScore = protocol.GraspScore{
139 GraspScore: item.UserGraspScore, 139 GraspScore: item.UserGraspScore,
140 - GraspScorePercent: item.UserGraspScore, 140 + GraspScorePercent: utils.DecimalToNumber(item.UserGraspScore),
141 } 141 }
142 rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId) 142 rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId)
143 rsp.ChanceTemplate = getTemplate(item.TemplateId) 143 rsp.ChanceTemplate = getTemplate(item.TemplateId)
@@ -153,7 +153,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve @@ -153,7 +153,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
153 Provider: user, 153 Provider: user,
154 GraspScore: protocol.GraspScore{ 154 GraspScore: protocol.GraspScore{
155 GraspScore: score, 155 GraspScore: score,
156 - GraspScorePercent: score, 156 + GraspScorePercent: utils.DecimalToNumber(score),
157 }, 157 },
158 Type: t, 158 Type: t,
159 } 159 }