Beispiel #1
0
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
}
Beispiel #2
0
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)
}
Beispiel #3
0
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)
}
Beispiel #4
0
func (f fakeCalculator) Calculate(d decimal.Decimal) decimal.Decimal {
	return d.Mul(rebatePercentage)
}
Beispiel #5
0
func (dep *Dependent) Calculate(quantity decimal.Decimal) decimal.Decimal {
	return quantity.Mul(dep.deduction)
}
Beispiel #6
0
func newton(z, x decimal.Decimal) decimal.Decimal {
	return z.Sub(z.Mul(z).Sub(x).Div(Const2.Mul(z)))
}
Beispiel #7
0
func MultiplyDecimalWithoutNew(decimalStartFloat, decimalFactor decimal.Decimal) (calculated decimal.Decimal) {
	calculated = decimalStartFloat.Mul(decimalFactor)

	return
}