2023-09-15 02:35:13 +00:00
|
|
|
package order
|
2023-09-15 09:58:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fusenapi/constants"
|
|
|
|
"fusenapi/model/gmodel"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetAmountCurrency(req *gmodel.AmountCurrency) (*float64, error) {
|
|
|
|
if req.CurrentCurrency == req.OriginalCurrency {
|
|
|
|
req.CurrentAmount = req.OriginalAmount
|
|
|
|
} else {
|
|
|
|
f1, err1 := strconv.ParseFloat(string(req.OriginalAmount), 64)
|
|
|
|
if err1 != nil {
|
|
|
|
return nil, err1
|
|
|
|
}
|
|
|
|
f2, err2 := strconv.ParseFloat(string(req.OriginalAmount), 64)
|
|
|
|
if err2 != nil {
|
|
|
|
return nil, err2
|
|
|
|
}
|
|
|
|
result := f1 * f2
|
|
|
|
req.CurrentAmount = constants.AmountUnit(strconv.FormatFloat(result, 'f', -1, 64))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|