func Upfutureprice(future_id string,
future_price, lowerLimitPrice, upperLimitPrice, preSettlementPrice float64,
updatetime time.Time) {
c := pool.Get()
if c == nil {
return
}
defer c.Close()
content := Fvprices{
P: future_price,
F: lowerLimitPrice,
C: upperLimitPrice,
S: preSettlementPrice,
T: updatetime.UnixNano() / 1e6,
}
js, _ := json.Marshal(content)
if _, err := c.Do("SET", future_id, js); err != nil {
fmt.Println("cannot save to redis:", err)
}
}
So obviously until the function
"Upfutureprice" everything is correct, for all four prices it receives are in float64 format. After running this program for one day, I just browse the redis using AnotherRedisDesktopManager via ssh port forwarding, and something strange happens as I clicking on various future_id key strings:
{
price:807
floor:720.6
ceiling:881
settle:"800.8000000000001"
time:1649726499000
}
{
price:"3691.0000000000005"
floor:3237
ceiling:4204
settle:3721
time:1649726910500
}
{
price:"15405.000000000004"
floor:13625
ceiling:17340
settle:15485
time:1649728303500
}
{
price:"800.4000000000001"
floor:720.6
ceiling:881
settle:"800.8000000000001"
time:1649728048000
}
Note quotations above. I wonder how encoding/json can made transformation from a float64 inside struct
Fvprices to a string instead? It seems that only long decimals would trigger such an error while short decimals won't:
{
price:2910
floor:2443.5
ceiling:3305.5
settle:2874.5
time:1649728261026
}
How could that happen? I am really puzzled.
Regards,
Zhaoxun