27 lines
491 B
Go
27 lines
491 B
Go
package util
|
|
|
|
import (
|
|
"math"
|
|
"strconv"
|
|
"regexp"
|
|
)
|
|
|
|
func StringToInt64(str string) int64 {
|
|
n, _ := strconv.ParseInt(str, 10,64)
|
|
return n
|
|
}
|
|
|
|
func round(num float64) int {
|
|
return int(num + math.Copysign(0.5, num))
|
|
}
|
|
|
|
func ToFixed(num float64, precision int) float64 {
|
|
output := math.Pow(10, float64(precision))
|
|
return float64(round(num*output)) / output
|
|
}
|
|
|
|
func ExtractInBracket(str string) string {
|
|
regex := regexp.MustCompile(`\[(.*?)\]`)
|
|
return regex.FindStringSubmatch(str)[1]
|
|
}
|