61 lines
981 B
Go
61 lines
981 B
Go
package domain
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
type ValidInt64 struct {
|
|
Value int64
|
|
Valid bool
|
|
}
|
|
type ValidInt struct {
|
|
Value int
|
|
Valid bool
|
|
}
|
|
|
|
type ValidString struct {
|
|
Value string
|
|
Valid bool
|
|
}
|
|
type ValidTime struct {
|
|
Value time.Time
|
|
Valid bool
|
|
}
|
|
type ValidBool struct {
|
|
Value bool
|
|
Valid bool
|
|
}
|
|
|
|
type Currency int64
|
|
|
|
// ToCurrency converts a float32 to Currency
|
|
func ToCurrency(f float32) Currency {
|
|
return Currency((f * 100) + 0.5)
|
|
}
|
|
|
|
// Float32 converts a Currency to float32
|
|
func (m Currency) Float32() float32 {
|
|
x := float32(m)
|
|
x = x / 100
|
|
return x
|
|
}
|
|
|
|
// String returns a formatted Currency value
|
|
func (m Currency) String() string {
|
|
x := float32(m)
|
|
x = x / 100
|
|
return fmt.Sprintf("$%.2f", x)
|
|
}
|
|
|
|
func CalculateWinnings(amount Currency, totalOdds float32) Currency {
|
|
|
|
vat := amount.Float32() * 0.15
|
|
stakeAfterVat := amount.Float32() - vat
|
|
possibleWin := stakeAfterVat * totalOdds
|
|
incomeTax := possibleWin * 0.15
|
|
|
|
return ToCurrency(possibleWin - incomeTax)
|
|
|
|
}
|