26 lines
595 B
Go
26 lines
595 B
Go
package order
|
|
|
|
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
|
|
}
|