作者 yangfu

把握分百分比取整

... ... @@ -15,3 +15,9 @@ func Decimal(value float64) float64 {
value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64)
return value
}
func DecimalToNumber(value float64) float64 {
value = decimal(value)
value, _ = strconv.ParseFloat(fmt.Sprintf("%.f", value), 64)
return value
}
... ...
... ... @@ -8,4 +8,10 @@ func TestDecimal(t *testing.T) {
t.Log(Decimal(1.7555555))
t.Log(Decimal(1.3555555))
t.Log(Decimal(1.3000001))
t.Log(DecimalToNumber(1.0))
t.Log(DecimalToNumber(1.4))
t.Log(DecimalToNumber(1.5))
t.Log(DecimalToNumber(1.6))
t.Log(DecimalToNumber(99.0))
}
... ...
... ... @@ -50,7 +50,7 @@ func AchievementPool(header *protocol.RequestHeader, request *protocol.Achieveme
Achievement: GetAchievementItem(header, item),
GraspScore: protocol.GraspScore{
GraspScore: item.UserGraspScore,
GraspScorePercent: item.UserGraspScore,
GraspScorePercent: utils.DecimalToNumber(item.UserGraspScore),
},
StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId),
ChanceTemplate: getTemplate(item.TemplateId),
... ... @@ -137,7 +137,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
rsp.Achievement = GetAchievementItem(header, item)
rsp.GraspScore = protocol.GraspScore{
GraspScore: item.UserGraspScore,
GraspScorePercent: item.UserGraspScore,
GraspScorePercent: utils.DecimalToNumber(item.UserGraspScore),
}
rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId)
rsp.ChanceTemplate = getTemplate(item.TemplateId)
... ... @@ -153,7 +153,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
Provider: user,
GraspScore: protocol.GraspScore{
GraspScore: score,
GraspScorePercent: score,
GraspScorePercent: utils.DecimalToNumber(score),
},
Type: t,
}
... ...