improve robustness and add unit tests

This commit is contained in:
MaysWind
2024-11-17 23:23:23 +08:00
parent a4b26374f4
commit ec0cb0bbb7
8 changed files with 66 additions and 1 deletions
@@ -174,6 +174,9 @@ func (e *SwissNationalBankExchangeRate) ToLatestExchangeRate(c core.Context) *mo
finalRate = finalRate / math.Pow10(unitExponent-1)
} else if unitExponent < 0 {
finalRate = finalRate * math.Pow10(-unitExponent)
} else if unitExponent == 0 {
log.Warnf(c, "[swiss_national_bank_datasource.ToLatestExchangeRate] unit exponent is zero, currency is %s", e.TargetCurrency)
return nil
}
if math.IsInf(finalRate, 0) {