~whereswaldon/ledger

887faa9276cccd6c16774acda24c0571b062a7c8 — Chris Howey 1 year, 8 months ago 5828893
fix: decimal division
2 files changed, 6 insertions(+), 1 deletions(-)

M internal/decimal/decimal.go
M internal/decimal/decimal_test.go
M internal/decimal/decimal.go => internal/decimal/decimal.go +1 -1
@@ 139,7 139,7 @@ func (d Decimal) Mul(d1 Decimal) Decimal {

// Div returns d / d1
func (d Decimal) Div(d1 Decimal) Decimal {
	return (d / d1) * scaleFactor
	return (d * scaleFactor) / d1
}

// Abs returns the absolute value of the decimal

M internal/decimal/decimal_test.go => internal/decimal/decimal_test.go +5 -0
@@ 24,6 24,11 @@ var testCases = []testCase{
		NewFromInt(48).Div(NewFromInt(8)).StringFixedBank(),
	},
	{
		"divide-1",
		NewFromFloat(11.111).StringFixedBank(),
		NewFromInt(100).Div(NewFromInt(9)).StringFixedBank(),
	},
	{
		"sum",
		NewFromFloat(234.56).StringFixedBank(),
		NewFromFloat(123.12).Add(NewFromInt(111)).Add(NewFromFloat(0.44)).StringFixedBank(),