🐛 fix: fix calculation accuracy
This commit is contained in:
parent
46aea4731b
commit
234fb1b118
@ -62,18 +62,14 @@ func (price *Price) GetOutput() float64 {
|
||||
return price.Output
|
||||
}
|
||||
|
||||
func (price *Price) FetchInputCurrencyPrice(rate float64) float64 {
|
||||
func (price *Price) FetchInputCurrencyPrice(rate float64) string {
|
||||
r := decimal.NewFromFloat(price.GetInput()).Mul(decimal.NewFromFloat(rate))
|
||||
v, _ := r.Float64()
|
||||
|
||||
return v
|
||||
return r.String()
|
||||
}
|
||||
|
||||
func (price *Price) FetchOutputCurrencyPrice(rate float64) float64 {
|
||||
func (price *Price) FetchOutputCurrencyPrice(rate float64) string {
|
||||
r := decimal.NewFromFloat(price.GetOutput()).Mul(decimal.NewFromFloat(rate))
|
||||
v, _ := r.Float64()
|
||||
|
||||
return v
|
||||
return r.String()
|
||||
}
|
||||
|
||||
func UpdatePrices(tx *gorm.DB, models []string, prices *Price) error {
|
||||
|
@ -129,13 +129,13 @@ func (q *Quota) completedQuotaConsumption(usage *types.Usage, tokenName string,
|
||||
}
|
||||
var modelRatioStr string
|
||||
if q.price.Type == model.TimesPriceType {
|
||||
modelRatioStr = fmt.Sprintf("$%g/次", q.price.FetchInputCurrencyPrice(model.DollarRate))
|
||||
modelRatioStr = fmt.Sprintf("$%s/次", q.price.FetchInputCurrencyPrice(model.DollarRate))
|
||||
} else {
|
||||
// 如果输入费率和输出费率一样,则只显示一个费率
|
||||
if q.price.GetInput() == q.price.GetOutput() {
|
||||
modelRatioStr = fmt.Sprintf("$%g/1k", q.price.FetchInputCurrencyPrice(model.DollarRate))
|
||||
modelRatioStr = fmt.Sprintf("$%s/1k", q.price.FetchInputCurrencyPrice(model.DollarRate))
|
||||
} else {
|
||||
modelRatioStr = fmt.Sprintf("$%g/1k (输入) | $%g/1k (输出)", q.price.FetchInputCurrencyPrice(model.DollarRate), q.price.FetchOutputCurrencyPrice(model.DollarRate))
|
||||
modelRatioStr = fmt.Sprintf("$%s/1k (输入) | $%s/1k (输出)", q.price.FetchInputCurrencyPrice(model.DollarRate), q.price.FetchOutputCurrencyPrice(model.DollarRate))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user