mirror of
https://github.com/riwiwa/muzi.git
synced 2026-02-28 11:56:57 -08:00
improve readability of the web package
This commit is contained in:
26
web/utils.go
Normal file
26
web/utils.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package web
|
||||
|
||||
// Functions used in the HTML templates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Subtracts two integers
|
||||
func sub(a int, b int) int {
|
||||
return a - b
|
||||
}
|
||||
|
||||
// Adds two integers
|
||||
func add(a int, b int) int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
// Put a comma in the thousands place, ten-thousands place etc.
|
||||
func formatInt(n int) string {
|
||||
if n < 1000 {
|
||||
return fmt.Sprintf("%d", n)
|
||||
} else {
|
||||
return formatInt(n/1000) + "," + fmt.Sprintf("%03d", n%1000)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user