feat: extract into remaining packages
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m19s
All checks were successful
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 1m19s
There has been a cyclic dependency. transaction -> treasure_chest -> transaction_recurring -> transaction This has been temporarily solved by moving the GenerateTransactions function into the transaction package. In the future, this function has to be rewritten to use a proper Service insteas of direct DB access or replaced with a different system entirely.
This commit is contained in:
36
internal/core/format.go
Normal file
36
internal/core/format.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func FormatEuros(balance int64) string {
|
||||
prefix := ""
|
||||
if balance < 0 {
|
||||
prefix = "- "
|
||||
balance = -balance
|
||||
}
|
||||
|
||||
n := float64(balance) / 100
|
||||
s := fmt.Sprintf("%.2f", n) // "1234567.89"
|
||||
|
||||
parts := strings.Split(s, ".")
|
||||
intPart := parts[0]
|
||||
fracPart := parts[1]
|
||||
|
||||
var result strings.Builder
|
||||
numberOfSeperators := len(intPart) % 3
|
||||
if numberOfSeperators == 0 {
|
||||
result.WriteString(intPart)
|
||||
} else {
|
||||
for i := range intPart {
|
||||
if i > 0 && (i-numberOfSeperators)%3 == 0 {
|
||||
result.WriteString(",")
|
||||
}
|
||||
result.WriteByte(intPart[i])
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + result.String() + "." + fracPart + " €"
|
||||
}
|
||||
Reference in New Issue
Block a user