func (c *Converter) genConvert(value decimal.Decimal, from, to Currency, at *time.Time) (decimal.Decimal, error) { var t time.Time if at == nil { t = time.Now().UTC() } else { t = *at } var usd decimal.Decimal if from == USD { usd = value } else { fromRate, err := c.ex.Get(t, from) if err != nil { return decimal.Zero, err } usd = value.Mul(fromRate.ToUSD) } if to == USD { return usd, nil } toRate, err := c.ex.Get(t, to) if err != nil { return decimal.Zero, err } return usd.Mul(toRate.FromUSD), nil }
func (irrf *IRRF) Calculate(grossSalary decimal.Decimal) decimal.Decimal { for _, irrfInterval := range irrf.irrfRange { if grossSalary.Cmp(irrfInterval.Lower) >= 0 && grossSalary.Cmp(irrfInterval.Upper) <= 0 { return grossSalary.Mul(irrfInterval.Aliquot).Sub(irrfInterval.Deduction) } } lastIRRFInterval := irrf.irrfRange[len(irrf.irrfRange)-1] return grossSalary.Mul(lastIRRFInterval.Aliquot).Sub(lastIRRFInterval.Deduction) }
func (inss *INSS) Calculate(grossSalary decimal.Decimal) decimal.Decimal { for _, inssInterval := range inss.inssRange { if grossSalary.Cmp(inssInterval.Lower) >= 0 && grossSalary.Cmp(inssInterval.Upper) <= 0 { return grossSalary.Mul(inssInterval.Aliquot) } } lastINSSInterval := inss.inssRange[len(inss.inssRange)-1] return lastINSSInterval.Upper.Mul(lastINSSInterval.Aliquot) }
func (f fakeCalculator) Calculate(d decimal.Decimal) decimal.Decimal { return d.Mul(rebatePercentage) }
func (dep *Dependent) Calculate(quantity decimal.Decimal) decimal.Decimal { return quantity.Mul(dep.deduction) }
func newton(z, x decimal.Decimal) decimal.Decimal { return z.Sub(z.Mul(z).Sub(x).Div(Const2.Mul(z))) }
func MultiplyDecimalWithoutNew(decimalStartFloat, decimalFactor decimal.Decimal) (calculated decimal.Decimal) { calculated = decimalStartFloat.Mul(decimalFactor) return }