Fix multiplication instead of division
This commit is contained in:
parent
487aa89f18
commit
f09a2a4ca7
@ -192,7 +192,6 @@ func (h *Handler) calculateBalances(c *gin.Context, budget postgres.Budget, firs
|
||||
categoryWithBalance.Activity = bal.Transactions
|
||||
categoryWithBalance.Assigned = bal.Assignments
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// do not show hidden categories
|
||||
|
@ -44,7 +44,7 @@ func (n Numeric) IsZero() bool {
|
||||
}
|
||||
|
||||
func (n Numeric) MatchExp(exp int32) Numeric {
|
||||
diffExp := exp - n.Exp
|
||||
diffExp := n.Exp - exp
|
||||
factor := big.NewInt(0).Exp(big.NewInt(10), big.NewInt(int64(diffExp)), nil)
|
||||
return Numeric{pgtype.Numeric{
|
||||
Exp: exp,
|
||||
@ -55,34 +55,36 @@ func (n Numeric) MatchExp(exp int32) Numeric {
|
||||
}
|
||||
|
||||
func (n Numeric) Sub(o Numeric) Numeric {
|
||||
if n.Exp > o.Exp {
|
||||
o = o.MatchExp(n.Exp)
|
||||
} else if n.Exp < o.Exp {
|
||||
n = n.MatchExp(o.Exp)
|
||||
left := n
|
||||
right := o
|
||||
if n.Exp < o.Exp {
|
||||
right = o.MatchExp(n.Exp)
|
||||
} else if n.Exp > o.Exp {
|
||||
left = n.MatchExp(o.Exp)
|
||||
}
|
||||
|
||||
if o.Exp == n.Exp {
|
||||
if left.Exp == right.Exp {
|
||||
return Numeric{pgtype.Numeric{
|
||||
Exp: n.Exp,
|
||||
Int: big.NewInt(0).Sub(o.Int, n.Int),
|
||||
Exp: left.Exp,
|
||||
Int: big.NewInt(0).Sub(left.Int, right.Int),
|
||||
}}
|
||||
}
|
||||
|
||||
panic("Cannot subtract with different exponents")
|
||||
}
|
||||
func (n Numeric) Add(o Numeric) Numeric {
|
||||
fmt.Println("N", n, "O", o)
|
||||
if n.Exp > o.Exp {
|
||||
o = o.MatchExp(n.Exp)
|
||||
} else if n.Exp < o.Exp {
|
||||
n = n.MatchExp(o.Exp)
|
||||
left := n
|
||||
right := o
|
||||
if n.Exp < o.Exp {
|
||||
right = o.MatchExp(n.Exp)
|
||||
} else if n.Exp > o.Exp {
|
||||
left = n.MatchExp(o.Exp)
|
||||
}
|
||||
|
||||
fmt.Println("NM", n, "OM", o)
|
||||
if o.Exp == n.Exp {
|
||||
if left.Exp == right.Exp {
|
||||
return Numeric{pgtype.Numeric{
|
||||
Exp: n.Exp,
|
||||
Int: big.NewInt(0).Add(o.Int, n.Int),
|
||||
Exp: left.Exp,
|
||||
Int: big.NewInt(0).Add(left.Int, right.Int),
|
||||
}}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user