修改价格类型为int64,int32不够用(如单日总成交金额,会变成负数)

This commit is contained in:
injoyai
2024-10-31 08:39:31 +08:00
parent 0939f69398
commit fc604d1eff
2 changed files with 4 additions and 7 deletions

View File

@@ -10,7 +10,7 @@ type StockMinuteTradeResp struct {
List []*StockMinuteTrade List []*StockMinuteTrade
} }
// StockMinuteTrade 分时成交todo 时间没有到秒,客户端上也没有 // StockMinuteTrade 分时成交todo 时间没有到秒,客户端上也没有,东方客户端能显示秒
type StockMinuteTrade struct { type StockMinuteTrade struct {
Time string //时间 Time string //时间
Price Price //价格 Price Price //价格
@@ -20,7 +20,7 @@ type StockMinuteTrade struct {
} }
func (this *StockMinuteTrade) String() string { func (this *StockMinuteTrade) String() string {
return fmt.Sprintf("%s \t%s \t%-6s \t%-6d(手) \t%-4d(单) \t%-4s", this.Time, this.Price, FloatUnitString(float64(this.Amount2())/100), this.Volume, this.Number, this.StatusString()) return fmt.Sprintf("%s \t%s \t%-6s \t%-6d(手) \t%-4d(单) \t%-4s", this.Time, this.Price, this.Amount(), this.Volume, this.Number, this.StatusString())
} }
// Amount 成交额 // Amount 成交额
@@ -28,10 +28,6 @@ func (this *StockMinuteTrade) Amount() Price {
return this.Price * Price(this.Volume) * 100 return this.Price * Price(this.Volume) * 100
} }
func (this *StockMinuteTrade) Amount2() int64 {
return this.Price.Int64() * int64(this.Volume) * 100
}
func (this *StockMinuteTrade) StatusString() string { func (this *StockMinuteTrade) StatusString() string {
switch this.Status { switch this.Status {
case 0: case 0:

View File

@@ -5,7 +5,7 @@ import (
) )
// Price 价格,单位分,分时成交的总金额可能会超出范围后续改成int64 // Price 价格,单位分,分时成交的总金额可能会超出范围后续改成int64
type Price int32 type Price int64
func (this Price) Float64() float64 { func (this Price) Float64() float64 {
return float64(this) / 100 return float64(this) / 100
@@ -16,6 +16,7 @@ func (this Price) Int64() int64 {
} }
func (this Price) String() string { func (this Price) String() string {
return fmt.Sprintf("%s元", FloatUnitString(this.Float64()))
return fmt.Sprintf("%0.2f元", this.Float64()) return fmt.Sprintf("%0.2f元", this.Float64())
} }