Skip to content

Commit

Permalink
fix json Inf
Browse files Browse the repository at this point in the history
  • Loading branch information
axiaoxin committed Nov 21, 2021
1 parent 65c45ab commit 8557ff7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions cron/eastmoney_funds_list.json

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions datacenter/eastmoney/fund_info_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package eastmoney

import (
"encoding/json"
"testing"

"github.com/stretchr/testify/require"
)

func TestQueryFundInfo(t *testing.T) {
data, err := _em.QueryFundInfo(_ctx, "011377")
data, err := _em.QueryFundInfo(_ctx, "013781")
require.Nil(t, err)
require.NotEmpty(t, data)
t.Log("data:", data)
t.Logf("data:%+v", data)
_, err = json.Marshal(data)
require.Nil(t, err)
}
4 changes: 3 additions & 1 deletion models/fund.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ func NewFund(ctx context.Context, efund *eastmoney.RespFundInfo) *Fund {
pfm := FundPerformance{}
for _, d := range efund.Jdzf.Datas {
rankRatio := interfaceToFloat64(ctx, interfaceToFloat64(ctx, d.Rank)) / interfaceToFloat64(ctx, d.Sc)
if math.IsNaN(rankRatio) {

// Note that a runtime 1.0 / 0.0 is +Inf
if math.IsNaN(rankRatio) || math.IsInf(rankRatio, 0) {
rankRatio = 0.0
}
rankRatio = rankRatio * 100.0 // %
Expand Down

0 comments on commit 8557ff7

Please sign in to comment.