init project
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FormatCurrency(value float64) string {
|
||||
currencyStr := strconv.FormatFloat(value, 'f', 2, 64)
|
||||
split := strings.Split(currencyStr, ".")
|
||||
n := len(split[0])
|
||||
if n <= 3 {
|
||||
return fmt.Sprintf("Rp %s,%s", split[0], split[1])
|
||||
}
|
||||
var result []string
|
||||
for i := 0; i < n; i += 3 {
|
||||
end := n - i
|
||||
start := end - 3
|
||||
if start < 0 {
|
||||
start = 0
|
||||
}
|
||||
result = append([]string{split[0][start:end]}, result...)
|
||||
}
|
||||
currencyStr = strings.Join(result, ".")
|
||||
return fmt.Sprintf("Rp %s,%s", currencyStr, split[1])
|
||||
}
|
||||
|
||||
const charset = "abcdefghijklmnopqrstuvwxyz" +
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
var seededRand *rand.Rand = rand.New(
|
||||
rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
func GenerateRandomString(length int) string {
|
||||
b := make([]byte, length)
|
||||
for i := range b {
|
||||
b[i] = charset[seededRand.Intn(len(charset))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
Reference in New Issue
Block a user