mirror of
https://github.com/gabehf/BudgetBuddy.git
synced 2026-03-13 09:20:37 -07:00
api for initial widgets
This commit is contained in:
parent
36f751a69f
commit
4aa8a2f822
14 changed files with 864 additions and 11 deletions
8
money/currency.go
Normal file
8
money/currency.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package money
|
||||
|
||||
type Currency string
|
||||
|
||||
const (
|
||||
USD Currency = "USD"
|
||||
CAD = "CAD"
|
||||
)
|
||||
31
money/money.go
Normal file
31
money/money.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package money
|
||||
|
||||
type Money struct {
|
||||
Currency Currency `json:"currency" bson:"currency"`
|
||||
Whole int `json:"whole" bson:"whole"`
|
||||
Decimal int `json:"decimal" bson:"decimal"`
|
||||
}
|
||||
|
||||
// add x to y
|
||||
func Add(x, y Money) Money {
|
||||
x.Decimal += y.Decimal
|
||||
if x.Decimal >= 100 {
|
||||
x.Whole++
|
||||
x.Decimal -= 100
|
||||
}
|
||||
x.Whole += y.Whole
|
||||
|
||||
return x
|
||||
}
|
||||
|
||||
// subtract x from y
|
||||
func Subtract(x, y Money) Money {
|
||||
x.Decimal = y.Decimal - x.Decimal
|
||||
if x.Decimal < 0 {
|
||||
x.Whole++
|
||||
x.Decimal += 100
|
||||
}
|
||||
x.Whole = y.Whole - x.Whole
|
||||
|
||||
return x
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue